diff --git a/www/assets/audio/Enter the Woods.mp3 b/www/assets/audio/Enter the Woods.mp3 new file mode 100644 index 0000000..0263d45 Binary files /dev/null and b/www/assets/audio/Enter the Woods.mp3 differ diff --git a/www/assets/audio/Heroes March.mp3 b/www/assets/audio/Heroes March.mp3 new file mode 100644 index 0000000..ac7ee68 Binary files /dev/null and b/www/assets/audio/Heroes March.mp3 differ diff --git a/www/js/main.js b/www/js/main.js index 2341b77..89467d1 100644 --- a/www/js/main.js +++ b/www/js/main.js @@ -318,6 +318,17 @@ function getTeamColorFromId(id) { return getTeamInfoFromId(id)['color']; } +/** + * Get the actual path to the www folder. Includes trailing slash. + * http://stackoverflow.com/a/35782322/2534036 + */ +function getWwwFolderPath() { + var path = window.location.pathname; + var sizefilename = path.length - (path.lastIndexOf("/")+1); + path = path.substr( path, path.length - sizefilename ); + return path; +}; + // Handle back button to close things document.addEventListener("backbutton", function (event) { if (currentscreen == "munzeelink") { diff --git a/www/screens/home.html b/www/screens/home.html index 93358df..3af71f1 100644 --- a/www/screens/home.html +++ b/www/screens/home.html @@ -127,8 +127,43 @@ $('#found-box-2').click(function (e) { $('#found-box').fadeOut('fast'); }); - + updateStatusBarColor(); + + + + var AUDIO_WAIT_SECONDS = 10; + var audio_stay_stopped = false; + + var audio_1 = new Media(getWwwFolderPath() + "assets/audio/Heroes March.mp3", null, null, function (status) { + if ((status == Media.MEDIA_NONE || status == Media.MEDIA_STOPPED) && !audio_stay_stopped) { + setTimeout(playBackgroundAudio(audio_2), AUDIO_WAIT_SECONDS * 1000); + } + }); + + var audio_2 = new Media(getWwwFolderPath() + "assets/audio/Enter the Woods.mp3", null, null, function (status) { + if ((status == Media.MEDIA_NONE || status == Media.MEDIA_STOPPED) && !audio_stay_stopped) { + setTimeout(playBackgroundAudio(audio_1), AUDIO_WAIT_SECONDS * 1000); + } + }); + + document.addEventListener("pause", function () { + audio_1.stop(); + audio_2.stop(); + audio_stay_stopped = true; + }); + document.addEventListener("resume", function () { + audio_stay_stopped = false; + playBackgroundAudio(audio_2); + }); + + function playBackgroundAudio(audiovar) { + setTimeout(function () { + audiovar.play(); + }, AUDIO_WAIT_SECONDS * 1000); + } + + playBackgroundAudio(audio_2);