Skip to content

Commit

Permalink
fix invalid state error in safari when trying to stop background music
Browse files Browse the repository at this point in the history
  • Loading branch information
orsi committed Jun 21, 2020
1 parent f6b7a35 commit 2a7f844
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion script/audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ var AudioEngine = {
var fadeTime = AudioEngine._audioContext.currentTime + AudioEngine.FADE_TIME;

// fade out current background music
if (AudioEngine._currentBackgroundMusic) {
if (AudioEngine._currentBackgroundMusic &&
AudioEngine._currentBackgroundMusic.source &&
AudioEngine._currentBackgroundMusic.source.playbackState !== 0) {
var currentBackgroundGainValue = AudioEngine._currentBackgroundMusic.envelope.gain.value;
AudioEngine._currentBackgroundMusic.envelope.gain.cancelScheduledValues(AudioEngine._audioContext.currentTime);
AudioEngine._currentBackgroundMusic.envelope.gain.setValueAtTime(currentBackgroundGainValue, AudioEngine._audioContext.currentTime);
Expand Down

0 comments on commit 2a7f844

Please sign in to comment.