From 48389653d784b594c25d9fdeb2475b2e82bf0e0f Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Thu, 25 Sep 2014 15:38:49 -0400 Subject: [PATCH] Hack for if autoplay is disabled --- assets/scripts/africa.js | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/assets/scripts/africa.js b/assets/scripts/africa.js index c268de0..e47e0aa 100644 --- a/assets/scripts/africa.js +++ b/assets/scripts/africa.js @@ -1,14 +1,7 @@ -var playing = false; +var sound = null; +var playing = true; var control = document.getElementById('control'); var background = document.getElementById('background'); -var sound = new Howl({ - urls: ['assets/audio/africa.ogg', 'assets/audio/africa.m4a'], - autoplay: true, - loop: true, - onload: function() { - setTimeout(makeItPlay, 500); - } -}); function toggle() { if(playing) { @@ -24,6 +17,16 @@ function toggle() { function load() { makeItRain(); + makeItPlay(); +} + +function makeItPlay() { + sound = new Howl({ + urls: ['assets/audio/africa.ogg', 'assets/audio/africa.m4a'], + autoplay: true, + loop: true + }); + setTimeout(enableToggle, 2500); } function makeItRain() { @@ -37,9 +40,10 @@ function makeItRain() { background.crossOrigin = 'anonymous'; } -var makeItPlay = function() { - if(sound.pos() === 0) { +var enableToggle = function() { + if(0 === sound.pos()) { playing = false; + control.className = 'icon-play'; control.style.visibility = 'visible'; } }