Skip to content

Commit f37ba7c

Browse files
author
pandamicro
committed
Reformat code and improve CCAudio
1 parent 8f05415 commit f37ba7c

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

cocos2d/audio/CCAudio.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ cc.Audio = cc.Class.extend({
118118
cc.Audio.touchPlayList.push({ loop: loop, offset: offset, audio: this._element });
119119
}
120120

121-
if (cc.Audio.bindTouch === false) {
121+
if (cc.Audio.bindTouch === false && this._element.paused) {
122122
cc.Audio.bindTouch = true;
123123
// Listen to the touchstart body event and play the audio when necessary.
124124
cc.game.canvas.addEventListener('touchstart', cc.Audio.touchStart);
@@ -391,8 +391,6 @@ cc.Audio.WebAudio.prototype = {
391391
if (audio)
392392
return cb(null, audio);
393393

394-
var i;
395-
396394
if (cc.loader.audioPath)
397395
realUrl = cc.path.join(cc.loader.audioPath, realUrl);
398396

@@ -528,6 +526,12 @@ cc.Audio.WebAudio.prototype = {
528526
stopMusic: function(releaseData){
529527
var audio = this._currMusic;
530528
if (audio) {
529+
var list = cc.Audio.touchPlayList;
530+
for (var i=list.length-1; i>=0; --i) {
531+
if (this[i] && this[i].audio === audio._element)
532+
list.splice(i, 1);
533+
}
534+
531535
audio.stop();
532536
this._currMusic = null;
533537
if (releaseData)
@@ -541,7 +545,7 @@ cc.Audio.WebAudio.prototype = {
541545
* //example
542546
* cc.audioEngine.pauseMusic();
543547
*/
544-
pauseMusic: function(){
548+
pauseMusic: function () {
545549
var audio = this._currMusic;
546550
if (audio)
547551
audio.pause();
@@ -553,7 +557,7 @@ cc.Audio.WebAudio.prototype = {
553557
* //example
554558
* cc.audioEngine.resumeMusic();
555559
*/
556-
resumeMusic: function(){
560+
resumeMusic: function () {
557561
var audio = this._currMusic;
558562
if (audio)
559563
audio.resume();
@@ -649,9 +653,7 @@ cc.Audio.WebAudio.prototype = {
649653
effectList = this._audioPool[url] = [];
650654
}
651655

652-
var i;
653-
654-
for (i = 0; i < effectList.length; i++) {
656+
for (var i = 0; i < effectList.length; i++) {
655657
if (!effectList[i].getPlaying()) {
656658
break;
657659
}

0 commit comments

Comments
 (0)