diff --git a/www/assets/audio/Enter the Woods.mp3 b/www/assets/audio/Enter the Woods.mp3 index 0263d45..e9a9676 100644 Binary files a/www/assets/audio/Enter the Woods.mp3 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 index ac7ee68..7f15ff8 100644 Binary files a/www/assets/audio/Heroes March.mp3 and b/www/assets/audio/Heroes March.mp3 differ diff --git a/www/assets/audio/Sisters of Snow Assent.mp3 b/www/assets/audio/Sisters of Snow Assent.mp3 new file mode 100644 index 0000000..12c4789 Binary files /dev/null and b/www/assets/audio/Sisters of Snow Assent.mp3 differ diff --git a/www/assets/audio/We Dream of Booty.mp3 b/www/assets/audio/We Dream of Booty.mp3 new file mode 100644 index 0000000..d11156c Binary files /dev/null and b/www/assets/audio/We Dream of Booty.mp3 differ diff --git a/www/index.html b/www/index.html index 558b881..84b39ab 100644 --- a/www/index.html +++ b/www/index.html @@ -61,6 +61,7 @@ + diff --git a/www/js/music.js b/www/js/music.js new file mode 100644 index 0000000..4226ce2 --- /dev/null +++ b/www/js/music.js @@ -0,0 +1,57 @@ +/* + * Copyright 2016 Netsyms Technologies. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +var AUDIO_WAIT_SECONDS = 10; +var audio_stay_stopped = false; +var audio_doneplaying = true; +var audio; + +var MUSIC_DIR = getWwwFolderPath() + "assets/audio/"; + +function queuesong(song) { + audio = new Media(MUSIC_DIR + song, null, null, function (status) { + if ((status == Media.MEDIA_NONE || status == Media.MEDIA_STOPPED) && !audio_stay_stopped) { + audio_doneplaying = true; + setTimeout(playAudio, AUDIO_WAIT_SECONDS * 1000); + } + }); +} + +function playAudio() { + if (audio_doneplaying) { + if (rawWeatherData.icon == "snow" || rawWeatherData.icon == "fog") { + queuesong("Sisters of Snow Assent.mp3"); + } else if (rawWeatherData.icon == "rain" || terrainType == 0) { + queuesong("We Dream of Booty.mp3"); + } else if (terrainType >= 1 && terrainType <= 5) { + queuesong("Enter the Woods.mp3"); + } else { + queuesong("Heroes March.mp3"); + } + } + audio.play({playAudioWhenScreenIsLocked: false}); +} + +document.addEventListener("pause", function () { + audio.pause(); + audio_doneplaying = false; + audio_stay_stopped = true; +}); +document.addEventListener("resume", function () { + audio_stay_stopped = false; + playAudio(); +}); \ No newline at end of file diff --git a/www/screens/home.html b/www/screens/home.html index 90c8f52..9fd8cb2 100644 --- a/www/screens/home.html +++ b/www/screens/home.html @@ -135,41 +135,8 @@ }); 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); + + setTimeout(playAudio, 10*1000);