Skip to content

Commit eb8e61d

Browse files
authored
Merge pull request #3430 from VisualSJ/develop-audio-playThenPause
Fixed a bug about pauseMusic
2 parents 4ef4dbf + b5748c3 commit eb8e61d

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

CCBoot.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -2349,8 +2349,7 @@ cc.game = /** @lends cc.game# */{
23492349
this._paused = true;
23502350
// Pause audio engine
23512351
if (cc.audioEngine) {
2352-
cc.audioEngine.stopAllEffects();
2353-
cc.audioEngine.pauseMusic();
2352+
cc.audioEngine._pausePlaying();
23542353
}
23552354
// Pause main loop
23562355
if (this._intervalId)
@@ -2366,7 +2365,7 @@ cc.game = /** @lends cc.game# */{
23662365
this._paused = false;
23672366
// Resume audio engine
23682367
if (cc.audioEngine) {
2369-
cc.audioEngine.resumeMusic();
2368+
cc.audioEngine._resumePlaying();
23702369
}
23712370
// Resume main loop
23722371
this._runMainLoop();

cocos2d/audio/CCAudio.js

+18-5
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
* Encapsulate DOM and webAudio
8484
*/
8585
cc.Audio = cc.Class.extend({
86+
interruptPlay: false,
8687
src: null,
8788
_element: null,
8889
_AUDIO_TYPE: "AUDIO",
@@ -110,7 +111,10 @@ cc.Audio = cc.Class.extend({
110111
},
111112

112113
play: function (offset, loop) {
113-
if (!this._element) return;
114+
if (!this._element) {
115+
this.interruptPlay = false;
116+
return;
117+
}
114118
this._element.loop = loop;
115119
this._element.play();
116120
if (this._AUDIO_TYPE === 'AUDIO' && this._element.paused) {
@@ -131,7 +135,10 @@ cc.Audio = cc.Class.extend({
131135
},
132136

133137
stop: function () {
134-
if (!this._element) return;
138+
if (!this._element) {
139+
this.interruptPlay = true;
140+
return;
141+
}
135142
this._element.pause();
136143
try {
137144
this._element.currentTime = 0;
@@ -140,12 +147,18 @@ cc.Audio = cc.Class.extend({
140147
},
141148

142149
pause: function () {
143-
if (!this._element) return;
150+
if (!this._element) {
151+
this.interruptPlay = true;
152+
return;
153+
}
144154
this._element.pause();
145155
},
146156

147157
resume: function () {
148-
if (!this._element) return;
158+
if (!this._element) {
159+
this.interruptPlay = false;
160+
return;
161+
}
149162
this._element.play();
150163
},
151164

@@ -520,7 +533,7 @@ cc.Audio.WebAudio.prototype = {
520533
var audio = cc.loader.getRes(url);
521534
if (!audio) {
522535
cc.loader.load(url, function () {
523-
if (!audio.getPlaying()) {
536+
if (!audio.getPlaying() && !audio.interruptPlay) {
524537
audio.setVolume(musicVolume);
525538
audio.play(0, loop || false);
526539
}

0 commit comments

Comments
 (0)