@@ -503,6 +503,7 @@ cc.Audio.WebAudio.prototype = {
503
503
return false ;
504
504
} ,
505
505
506
+ _waitLoadPlayFlag : true ,
506
507
/**
507
508
* Play music.
508
509
* @param {String } url The path of the music file without filename extension.
@@ -512,15 +513,17 @@ cc.Audio.WebAudio.prototype = {
512
513
* cc.audioEngine.playMusic(path, false);
513
514
*/
514
515
playMusic : function ( url , loop ) {
516
+ this . _waitLoadPlayFlag = true ;
515
517
var bgMusic = this . _currMusic ;
516
518
if ( bgMusic && bgMusic . getPlaying ( ) ) {
517
519
bgMusic . stop ( ) ;
518
520
}
519
521
var musicVolume = this . _musicVolume ;
520
522
var audio = cc . loader . getRes ( url ) ;
523
+ var self = this ;
521
524
if ( ! audio ) {
522
525
cc . loader . load ( url , function ( ) {
523
- if ( ! audio . getPlaying ( ) ) {
526
+ if ( self . _waitLoadPlayFlag && ! audio . getPlaying ( ) ) {
524
527
audio . setVolume ( musicVolume ) ;
525
528
audio . play ( 0 , loop || false ) ;
526
529
}
@@ -542,6 +545,7 @@ cc.Audio.WebAudio.prototype = {
542
545
*/
543
546
stopMusic : function ( releaseData ) {
544
547
var audio = this . _currMusic ;
548
+ this . _waitLoadPlayFlag = false ;
545
549
if ( audio ) {
546
550
var list = cc . Audio . touchPlayList ;
547
551
for ( var i = list . length - 1 ; i >= 0 ; -- i ) {
@@ -564,6 +568,7 @@ cc.Audio.WebAudio.prototype = {
564
568
*/
565
569
pauseMusic : function ( ) {
566
570
var audio = this . _currMusic ;
571
+ this . _waitLoadPlayFlag = false ;
567
572
if ( audio )
568
573
audio . pause ( ) ;
569
574
} ,
0 commit comments