Commit f8071e7b authored by limingzhe's avatar limingzhe

fix: 切换时 去掉音频

parent 2ffb7e9d
......@@ -39,6 +39,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
// 所有全局变量 默认都是null
}
audioId = null;
initView() {
this.initBg();
......@@ -65,7 +66,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
if (this.data.audio && this.data.audio !== '') {
let girl_ske = cc.find('Canvas/girl_ske').getComponent(dragonBones.ArmatureDisplay);
girl_ske.playAnimation('speak', 0);
this.playAudioByUrl(this.data.audio, () => {
this.audioId = this.playAudioByUrl(this.data.audio, () => {
girl_ske.playAnimation('normal', 0);
});
} else {
......@@ -101,4 +102,10 @@ export default class SceneComponent extends MyCocosSceneComponent {
});
// callFunc('NS_select_game', { gameId: info.id });
}
onDestroy() {
if (this.audioId) {
cc.audioEngine.pause(this.audioId);
}
}
}
......@@ -163,9 +163,10 @@ export class MyCocosSceneComponent extends cc.Component {
}
playAudioByUrl(audio_url, cb = null) {
let audioId;
if (audio_url) {
cc.assetManager.loadRemote(audio_url, (err, audioClip) => {
const audioId = cc.audioEngine.play(audioClip, false, 0.8);
audioId = cc.audioEngine.play(audioClip, false, 0.8);
if (cb) {
cc.audioEngine.setFinishCallback(audioId, () => {
cb();
......@@ -175,5 +176,6 @@ export class MyCocosSceneComponent extends cc.Component {
}else{
cb && cb();
}
return audioId;
}
}
\ 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