Improved sound management

This commit is contained in:
Thomas FORGIONE 2015-05-12 11:21:06 +02:00
parent 849e23ee5d
commit 0124e485cb
1 changed files with 15 additions and 1 deletions

View File

@ -43,7 +43,21 @@ Coin.prototype.get = function() {
Coin.nextSound.play(); Coin.nextSound.play();
if (Coin.total === 9) { if (Coin.total === 9) {
// You got the last coin // 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 { } else {
Coin.nextSound = new Audio('/static/data/music/redcoins/' + Coin.total + '.mp3'); Coin.nextSound = new Audio('/static/data/music/redcoins/' + Coin.total + '.mp3');
Coin.nextSound.preload = "auto"; Coin.nextSound.preload = "auto";