Merge pull request #1206 from VisualSJ/v1.3_4413

Fixed a bug about audio volume
This commit is contained in:
Jare Guo
2016-10-17 18:19:51 +08:00
committed by GitHub
2 changed files with 31 additions and 1 deletions
+9 -1
View File
@@ -346,7 +346,15 @@ var WebAudioElement = function (buffer, audio) {
});
proto.__defineGetter__('volume', function () { return this._volume['gain'].value; });
proto.__defineSetter__('volume', function (num) { return this._volume['gain'].value = num; });
proto.__defineSetter__('volume', function (num) {
this._volume['gain'].value = num;
if (cc.sys.os === cc.sys.OS_IOS && !this.paused) {
// IOS must be stop webAudio
this.pause();
this.play();
}
return num;
});
proto.__defineGetter__('currentTime', function () {
if (this.paused) {
+22
View File
@@ -52,6 +52,10 @@ var AudioSource = cc.Class({
_volume: 1,
_mute: false,
_loop: false,
_pausedFlag: {
default: false,
serializable: false
},
/**
* !#en
@@ -188,6 +192,20 @@ var AudioSource = cc.Class({
}
},
_pausedCallback: function () {
if (!this.audio || this.audio.paused) return;
this.audio.pause();
this._pausedFlag = true;
},
_restoreCallback: function () {
if (!this.audio) return;
if (this._pausedFlag) {
this.audio.resume();
}
this._pausedFlag = false;
},
onEnable: function () {
if ( this.playOnLoad ) {
this.play();
@@ -196,10 +214,14 @@ var AudioSource = cc.Class({
this.audio.src = this._clip;
this.audio.preload();
}
cc.game.on(cc.game.EVENT_HIDE, this._pausedCallback, this);
cc.game.on(cc.game.EVENT_SHOW, this._restoreCallback, this);
},
onDisable: function () {
this.stop();
cc.game.off(cc.game.EVENT_HIDE, this._pausedCallback, this);
cc.game.off(cc.game.EVENT_SHOW, this._restoreCallback, this);
},
onDestroy: function () {