Skip to content

Commit

Permalink
[FIX] Don't resume 3d sounds when switching tabs, [FIX] Don't start s…
Browse files Browse the repository at this point in the history
…ounds when changing '3d' property
  • Loading branch information
vkalpias committed Dec 7, 2015
1 parent 4e70076 commit 4eeb950
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/audio/audio_channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ pc.extend(pc, function () {
this.manager.on('volumechange', this.onManagerVolumeChange, this);
this.manager.on('suspend', this.onManagerSuspend, this);
this.manager.on('resume', this.onManagerResume, this);

// suspend immediately if manager is suspended
if (this.manager.suspended)
this.onManagerSuspend();
},

/**
Expand Down Expand Up @@ -227,6 +231,10 @@ pc.extend(pc, function () {
this.manager.on('suspend', this.onManagerSuspend, this);
this.manager.on('resume', this.onManagerResume, this);

// suspend immediately if manager is suspended
if (this.manager.suspended)
this.onManagerSuspend();

},

pause: function () {
Expand Down
5 changes: 5 additions & 0 deletions src/audio/audio_channel3d.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ pc.extend(pc, function () {
this.source.connect(this.panner);
this.panner.connect(this.gain);
this.gain.connect(context.destination);

if (!this.loop) {
// mark source as paused when it ends
this.source.onended = this.pause.bind(this);
}
}
});
} else if (pc.AudioManager.hasAudio()) {
Expand Down
12 changes: 12 additions & 0 deletions src/framework/components/audiosource/audiosource_component.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,19 @@ pc.extend(pc, function () {
onSet3d: function (name, oldValue, newValue) {
if (oldValue !== newValue) {
if (this.system.initialized && this.currentSource) {
var paused = false;
var suspended = false;
if (this.channel) {
paused = this.channel.paused;
suspended = this.channel.suspended;
}

this.play(this.currentSource);

if (this.channel) {
this.channel.paused = paused;
this.channel.suspended = suspended;
}
}
}
},
Expand Down

0 comments on commit 4eeb950

Please sign in to comment.