From 4eeb9505a507e4d2d220ca1c8d3ec0e364bed0ae Mon Sep 17 00:00:00 2001 From: Vaios Kalpias-Ilias Date: Mon, 7 Dec 2015 11:50:23 +0200 Subject: [PATCH] [FIX] Don't resume 3d sounds when switching tabs, [FIX] Don't start sounds when changing '3d' property --- src/audio/audio_channel.js | 8 ++++++++ src/audio/audio_channel3d.js | 5 +++++ .../components/audiosource/audiosource_component.js | 12 ++++++++++++ 3 files changed, 25 insertions(+) diff --git a/src/audio/audio_channel.js b/src/audio/audio_channel.js index e423dca9b19..9feba027ce3 100644 --- a/src/audio/audio_channel.js +++ b/src/audio/audio_channel.js @@ -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(); }, /** @@ -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 () { diff --git a/src/audio/audio_channel3d.js b/src/audio/audio_channel3d.js index c1896809f9d..ce899d228d3 100644 --- a/src/audio/audio_channel3d.js +++ b/src/audio/audio_channel3d.js @@ -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()) { diff --git a/src/framework/components/audiosource/audiosource_component.js b/src/framework/components/audiosource/audiosource_component.js index 037c133bb4a..c74067d8e70 100644 --- a/src/framework/components/audiosource/audiosource_component.js +++ b/src/framework/components/audiosource/audiosource_component.js @@ -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; + } } } },