Add better music (now reacts to weather/terrain and has more music)

master
Skylar Ittner 8 years ago
parent 0a9d542a43
commit 67427a981b

Binary file not shown.

@ -61,6 +61,7 @@
<script src="js/leaflet.js"></script>
<script src="js/L.Control.Locate.min.js"></script>
<script src="js/leaflet.markercluster.js"></script>
<script src="js/music.js"></script>
</head>
<body>

@ -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();
});

@ -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);
</script>
<script src="js/location.js"></script>
<script src="js/user.js"></script>