Commit 912fb60f authored by 李维's avatar 李维

添加课程简介音频播放动画

parent 4a07559d
{
"__type__": "cc.AnimationClip",
"_name": "audioPlay",
"_objFlags": 0,
"_native": "",
"_duration": 1.0166666666666666,
"sample": 60,
"speed": 1,
"wrapMode": 2,
"curveData": {
"comps": {
"cc.Sprite": {
"spriteFrame": [
{
"frame": 0,
"value": {
"__uuid__": "e7613ee0-6552-4685-9da2-2086a30f6ba5"
}
},
{
"frame": 0.3333333333333333,
"value": {
"__uuid__": "7d0546e8-bfc5-4f8d-949b-942460801e63"
}
},
{
"frame": 0.6666666666666666,
"value": {
"__uuid__": "bc4f5af0-f203-4851-8968-0f0a1e47103e"
}
},
{
"frame": 1,
"value": {
"__uuid__": "e7613ee0-6552-4685-9da2-2086a30f6ba5"
}
}
]
}
}
},
"events": []
}
\ No newline at end of file
{
"ver": "2.1.0",
"uuid": "e061dd30-01a9-4011-bd01-594dd99fb4e1",
"subMetas": {}
}
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
// - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks: // Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
import { playAudioByUrl, getSprNodeByUrl, setSprNodeMaxLen, asyncCallNetworkApiGet, asyncCallNetworkApiPost, getSpriteFrimeByUrl, asyncDelay } from "./util"; import { playAudioByUrl, playAnimationOnNode, getSprNodeByUrl, setSprNodeMaxLen, asyncCallNetworkApiGet, asyncCallNetworkApiPost, getSpriteFrimeByUrl, asyncDelay } from "./util";
const { ccclass, property } = cc._decorator; const { ccclass, property } = cc._decorator;
...@@ -30,6 +30,8 @@ export default class LessonPreviewClass extends cc.Component { ...@@ -30,6 +30,8 @@ export default class LessonPreviewClass extends cc.Component {
btn_audio: cc.Node = null; btn_audio: cc.Node = null;
@property(cc.Label) @property(cc.Label)
lblAudio: cc.Label = null; lblAudio: cc.Label = null;
@property(cc.Node)
AniAudio: cc.Node = null;
onClickClose() { onClickClose() {
this.audio_url = null this.audio_url = null
...@@ -92,25 +94,29 @@ export default class LessonPreviewClass extends cc.Component { ...@@ -92,25 +94,29 @@ export default class LessonPreviewClass extends cc.Component {
if (this.curPageIndex < this.data.length) this.curPageIndex++ if (this.curPageIndex < this.data.length) this.curPageIndex++
this.refreshUI() this.refreshUI()
} }
isAudioPlaying = false isAudioPlaying = false
audio_url audio_url
playAudioId playAudioId
aniPlay = null;
onClickAudio() { onClickAudio() {
if (!this.audio_url) { if (!this.audio_url) {
return; return;
} }
if(this.isAudioPlaying) { if(this.isAudioPlaying) {
cc.audioEngine.stop(this.playAudioId); cc.audioEngine.stop(this.playAudioId);
this.aniPlay && this.aniPlay.stop()
this.isAudioPlaying = false; this.isAudioPlaying = false;
} else { } else {
this.isAudioPlaying = true; this.isAudioPlaying = true;
if (this.audio_url) { if (this.audio_url) {
cc.assetManager.loadRemote(this.audio_url, (err, audioClip) => { cc.assetManager.loadRemote(this.audio_url, (err, audioClip) => {
this.playAudioId = cc.audioEngine.play(audioClip, false, 0.8); this.playAudioId = cc.audioEngine.play(audioClip, false, 0.8);
this.aniPlay = playAnimationOnNode(this.AniAudio, "audioPlay");
cc.audioEngine.setFinishCallback(this.playAudioId, () => { cc.audioEngine.setFinishCallback(this.playAudioId, () => {
this.playAudioId = null this.playAudioId = null;
this.isAudioPlaying = false; this.isAudioPlaying = false;
this.aniPlay && this.aniPlay.stop()
}); });
}) })
} }
......
...@@ -46,6 +46,12 @@ export function exchangeNodePos(baseNode, targetNode) { ...@@ -46,6 +46,12 @@ export function exchangeNodePos(baseNode, targetNode) {
return baseNode.convertToNodeSpaceAR(targetNode._parent.convertToWorldSpaceAR(cc.v2(targetNode.x, targetNode.y))); return baseNode.convertToNodeSpaceAR(targetNode._parent.convertToWorldSpaceAR(cc.v2(targetNode.x, targetNode.y)));
} }
export function playAnimationOnNode(node, aniName) {
const animationState = node.getComponent(cc.Animation).getAnimationState(aniName);
animationState.play();
return animationState;
}
export function RandomInt(a, b = 0) { export function RandomInt(a, b = 0) {
let max = Math.max(a, b); let max = Math.max(a, b);
let min = Math.min(a, b); let min = Math.min(a, b);
......
{
"ver": "2.3.5",
"uuid": "eac4f663-9a0a-4ce5-9d97-e8d9d1035566",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 106,
"height": 34,
"platformSettings": {},
"subMetas": {
"ani_audio1": {
"ver": "1.0.4",
"uuid": "e7613ee0-6552-4685-9da2-2086a30f6ba5",
"rawTextureUuid": "eac4f663-9a0a-4ce5-9d97-e8d9d1035566",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 106,
"height": 34,
"rawWidth": 106,
"rawHeight": 34,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
{
"ver": "2.3.5",
"uuid": "873c5b57-fa49-4b16-8a76-9edff9d503fc",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 106,
"height": 34,
"platformSettings": {},
"subMetas": {
"ani_audio2": {
"ver": "1.0.4",
"uuid": "7d0546e8-bfc5-4f8d-949b-942460801e63",
"rawTextureUuid": "873c5b57-fa49-4b16-8a76-9edff9d503fc",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 106,
"height": 34,
"rawWidth": 106,
"rawHeight": 34,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
{
"ver": "2.3.5",
"uuid": "67188343-4d8b-4eab-8d4f-e237a94229a8",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 106,
"height": 34,
"platformSettings": {},
"subMetas": {
"ani_audio3": {
"ver": "1.0.4",
"uuid": "bc4f5af0-f203-4851-8968-0f0a1e47103e",
"rawTextureUuid": "67188343-4d8b-4eab-8d4f-e237a94229a8",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 106,
"height": 34,
"rawWidth": 106,
"rawHeight": 34,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment