Commit 172035aa authored by wangxin's avatar wangxin

播放声音前停止其他声音

parent dcaf6bc0
...@@ -129,7 +129,7 @@ cc.Class({ ...@@ -129,7 +129,7 @@ cc.Class({
getDefaultData() { getDefaultData() {
const dataJson = const dataJson =
'{"title":"hello","audio_title":"http://staging-teach.cdn.ireadabc.com/f7fb9f71ab7d460ac2f78c85efba7610.mp3","options":[{"pic_url":"http://staging-teach.cdn.ireadabc.com/004be996ea209e366951a7c4b6a3e55f.jpeg","audio_url":"http://staging-teach.cdn.ireadabc.com/0f0482ddb8c0d3329165ab0612683148.mp3"},{"pic_url":"http://staging-teach.cdn.ireadabc.com/785b0bc1766658373e4ebdcbd694a088.jpeg","audio_url":"http://staging-teach.cdn.ireadabc.com/784cd4188bf126d6c3c9395d9a807619.mp3"},{"pic_url":"http://staging-teach.cdn.ireadabc.com/5433aa00faced2d5e02f9cecce63ba09.jpeg","audio_url":"http://staging-teach.cdn.ireadabc.com/0f0482ddb8c0d3329165ab0612683148.mp3"},{"pic_url":"http://staging-teach.cdn.ireadabc.com/9298013cc63aa40035dbd18f1f8380a8.jpeg","audio_url":"http://staging-teach.cdn.ireadabc.com/784cd4188bf126d6c3c9395d9a807619.mp3"},{"pic_url":"http://staging-teach.cdn.ireadabc.com/9298013cc63aa40035dbd18f1f8380a8.jpeg","audio_url":"http://staging-teach.cdn.ireadabc.com/784cd4188bf126d6c3c9395d9a807619.mp3"},{"pic_url":"http://staging-teach.cdn.ireadabc.com/9298013cc63aa40035dbd18f1f8380a8.jpeg","audio_url":"http://staging-teach.cdn.ireadabc.com/784cd4188bf126d6c3c9395d9a807619.mp3"}]}'; '{"title":"hello","audio_title":"http://staging-teach.cdn.ireadabc.com/f7fb9f71ab7d460ac2f78c85efba7610.mp3","options":[{"pic_url":"http://staging-teach.cdn.ireadabc.com/004be996ea209e366951a7c4b6a3e55f.jpeg","audio_url":"http://staging-teach.cdn.ireadabc.com/fff5204fc774e932bcd597b4094b0852.mp3"},{"pic_url":"http://staging-teach.cdn.ireadabc.com/785b0bc1766658373e4ebdcbd694a088.jpeg","audio_url":"http://staging-teach.cdn.ireadabc.com/fff5204fc774e932bcd597b4094b0852.mp3"},{"pic_url":"http://staging-teach.cdn.ireadabc.com/5433aa00faced2d5e02f9cecce63ba09.jpeg","audio_url":"http://staging-teach.cdn.ireadabc.com/fff5204fc774e932bcd597b4094b0852.mp3"},{"pic_url":"http://staging-teach.cdn.ireadabc.com/9298013cc63aa40035dbd18f1f8380a8.jpeg","audio_url":"http://staging-teach.cdn.ireadabc.com/fff5204fc774e932bcd597b4094b0852.mp3"},{"pic_url":"http://staging-teach.cdn.ireadabc.com/9298013cc63aa40035dbd18f1f8380a8.jpeg","audio_url":"http://staging-teach.cdn.ireadabc.com/784cd4188bf126d6c3c9395d9a807619.mp3"},{"pic_url":"http://staging-teach.cdn.ireadabc.com/9298013cc63aa40035dbd18f1f8380a8.jpeg","audio_url":"http://staging-teach.cdn.ireadabc.com/784cd4188bf126d6c3c9395d9a807619.mp3"}]}';
const data = JSON.parse(dataJson); const data = JSON.parse(dataJson);
return data; return data;
}, },
......
...@@ -100,12 +100,14 @@ cc.Class({ ...@@ -100,12 +100,14 @@ cc.Class({
if (this._isContact && !this._soundOp.node.getComponent("op_sound")._isRight) { if (this._isContact && !this._soundOp.node.getComponent("op_sound")._isRight) {
if (this._isEnter) { if (this._isEnter) {
console.log("enter right"); console.log("enter right");
cc.game.emit("STOP_ALL_AUDIO");
this.playSound(0); this.playSound(0);
this._soundOp.node.getComponent("op_sound").correct(this._spriteFrame, this._width, this._height); this._soundOp.node.getComponent("op_sound").correct(this._spriteFrame, this._width, this._height);
this.node.destroy(); this.node.destroy();
} else { } else {
console.log("enter false"); console.log("enter false");
cc.game.emit("STOP_ALL_AUDIO");
this.playSound(1); this.playSound(1);
this.node.active = false; this.node.active = false;
this._soundOp.node.getComponent("op_sound").wrong(this._spriteFrame, this._width, this._height); this._soundOp.node.getComponent("op_sound").wrong(this._spriteFrame, this._width, this._height);
......
...@@ -35,6 +35,14 @@ cc.Class({ ...@@ -35,6 +35,14 @@ cc.Class({
_opPic: null, _opPic: null,
_isRight: false, _isRight: false,
_isPlaying: false, _isPlaying: false,
_curAudioId: 0,
},
onEnable() {
cc.game.on("STOP_ALL_AUDIO", this.onStopAudio, this);
},
onDisable() {
cc.game.off("STOP_ALL_AUDIO", this.onStopAudio, this);
}, },
/** /**
...@@ -42,11 +50,12 @@ cc.Class({ ...@@ -42,11 +50,12 @@ cc.Class({
*/ */
play() { play() {
if (this._soundUrl != "" && !this._isPlaying) { if (this._soundUrl != "" && !this._isPlaying) {
cc.game.emit("STOP_ALL_AUDIO");
this._isPlaying = true; this._isPlaying = true;
cc.assetManager.loadRemote(this._soundUrl, (err, audioClip) => { cc.assetManager.loadRemote(this._soundUrl, (err, audioClip) => {
const audioId = cc.audioEngine.play(audioClip, false, 0.8); this._curAudioId = cc.audioEngine.play(audioClip, false);
this.iconSound.getComponent(cc.Animation).play("icon_sound_play"); this.iconSound.getComponent(cc.Animation).play("icon_sound_play");
cc.audioEngine.setFinishCallback(audioId, () => { cc.audioEngine.setFinishCallback(this._curAudioId, () => {
this.iconSound.getComponent(cc.Animation).play("icon_sound_finish"); this.iconSound.getComponent(cc.Animation).play("icon_sound_finish");
this._isPlaying = false; this._isPlaying = false;
}); });
...@@ -106,4 +115,12 @@ cc.Class({ ...@@ -106,4 +115,12 @@ cc.Class({
this._opPic.node.getComponent("op_pic").resetPos(); this._opPic.node.getComponent("op_pic").resetPos();
}, 1.2); }, 1.2);
}, },
onStopAudio() {
if (this._isPlaying) {
this._isPlaying = false;
this.iconSound.getComponent(cc.Animation).play("icon_sound_finish");
cc.audioEngine.stopEffect(this._curAudioId);
}
},
}); });
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