Skip to content

Commit b54750a

Browse files
committed
Fixed a bug about pauseMusic
1 parent 92278e7 commit b54750a

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

cocos2d/audio/CCAudio.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ cc.Audio.WebAudio.prototype = {
503503
return false;
504504
},
505505

506+
_waitLoadPlayFlag: true,
506507
/**
507508
* Play music.
508509
* @param {String} url The path of the music file without filename extension.
@@ -512,15 +513,17 @@ cc.Audio.WebAudio.prototype = {
512513
* cc.audioEngine.playMusic(path, false);
513514
*/
514515
playMusic: function(url, loop){
516+
this._waitLoadPlayFlag = true;
515517
var bgMusic = this._currMusic;
516518
if (bgMusic && bgMusic.getPlaying()) {
517519
bgMusic.stop();
518520
}
519521
var musicVolume = this._musicVolume;
520522
var audio = cc.loader.getRes(url);
523+
var self = this;
521524
if (!audio) {
522525
cc.loader.load(url, function () {
523-
if (!audio.getPlaying()) {
526+
if (self._waitLoadPlayFlag && !audio.getPlaying()) {
524527
audio.setVolume(musicVolume);
525528
audio.play(0, loop || false);
526529
}
@@ -542,6 +545,7 @@ cc.Audio.WebAudio.prototype = {
542545
*/
543546
stopMusic: function(releaseData){
544547
var audio = this._currMusic;
548+
this._waitLoadPlayFlag = false;
545549
if (audio) {
546550
var list = cc.Audio.touchPlayList;
547551
for (var i=list.length-1; i>=0; --i) {
@@ -564,6 +568,7 @@ cc.Audio.WebAudio.prototype = {
564568
*/
565569
pauseMusic: function () {
566570
var audio = this._currMusic;
571+
this._waitLoadPlayFlag = false;
567572
if (audio)
568573
audio.pause();
569574
},

0 commit comments

Comments
 (0)