diff --git a/assets/scripts/africa.js b/assets/scripts/africa.js index 74b5c55..ab8cc5a 100644 --- a/assets/scripts/africa.js +++ b/assets/scripts/africa.js @@ -1,31 +1,29 @@ -var playing = false; -var control = document.getElementById('control'); +var playing = false; +var control = document.getElementById('control'); var background = document.getElementById('background'); - -var sound = new Howl({ +var sound = new Howl({ urls: ['assets/audio/africa.ogg', 'assets/audio/africa.m4a'], autoplay: true, - loop: true + loop: true, + onload: function() { + setTimeout(makeItPlay, 5); + } }); function toggle() { if(playing) { sound.pause(); - playing = false; + playing = false; control.className = 'icon-play'; } else { sound.play(); - playing = true; + playing = true; control.className = 'icon-pause'; } } function load() { makeItRain(); - if(!isMobile.any()) { - playing = true; - control.style.visibility = 'hidden'; - } } function makeItRain() { @@ -39,12 +37,9 @@ function makeItRain() { background.crossOrigin = 'anonymous'; } -var isMobile = { - Android: function() { return navigator.userAgent.match(/Android/i); }, - BlackBerry: function() { return navigator.userAgent.match(/BlackBerry/i); }, - iOS: function() { return navigator.userAgent.match(/iPhone|iPad|iPod/i); }, - Opera: function() { return navigator.userAgent.match(/Opera Mini/i); }, - Windows: function() { return navigator.userAgent.match(/IEMobile/i); }, - any: function() { return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows()); } -}; - +var makeItPlay = function() { + if(sound.pos() === 0) { + playing = false; + control.style.visibility = 'visible'; + } +} diff --git a/assets/styles/style.css b/assets/styles/style.css index 0f9bafd..5fbdeb3 100644 --- a/assets/styles/style.css +++ b/assets/styles/style.css @@ -16,6 +16,7 @@ html, body, img, #container { } #control { + visibility: hidden; display: inline-block; border-radius: 10px; diff --git a/index.html b/index.html index 4442e49..f714a55 100644 --- a/index.html +++ b/index.html @@ -13,7 +13,7 @@