From 0124e485cbc32317d1ea89136ba98fa2a4df6bb6 Mon Sep 17 00:00:00 2001 From: Thomas FORGIONE Date: Tue, 12 May 2015 11:21:06 +0200 Subject: [PATCH] Improved sound management --- static/js/prototype/Coin.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/static/js/prototype/Coin.js b/static/js/prototype/Coin.js index 38ee8e1..04967d4 100644 --- a/static/js/prototype/Coin.js +++ b/static/js/prototype/Coin.js @@ -43,7 +43,21 @@ Coin.prototype.get = function() { Coin.nextSound.play(); if (Coin.total === 9) { // You got the last coin - setTimeout(function() {Coin.lastSound.play();}, Coin.nextSound.duration + 1000); + var music = document.getElementById('music'); + var wasPlaying = !music.paused; + music.pause(); + (function(music, wasPlaying) { + setTimeout(function() { + Coin.lastSound.play(); + (function(wasPlaying) { + setTimeout(function() { + if (wasPlaying) { + music.play(); + } + }, Coin.lastSound.duration*1000); + })(wasPlaying); + }, Coin.nextSound.duration*1000); + })(music, wasPlaying); } else { Coin.nextSound = new Audio('/static/data/music/redcoins/' + Coin.total + '.mp3'); Coin.nextSound.preload = "auto";