sound-cards/static/js/app.js

26 lines
478 B
JavaScript
Raw Permalink Normal View History

2017-02-10 12:41:41 +00:00
const min_playtime = 1000
const fade_threshold = 2000
function preload_audio (file) {
return new Howl({
src: [file]
})
}
function play_audio (sound, timeout, callback) {
sound.play()
if (timeout) {
if (timeout - fade_threshold > min_playtime) {
setTimeout(function () {
sound.fade(sound.volume(), 0, fade_threshold)
}, timeout - fade_threshold)
}
setTimeout(function () {
sound.stop()
callback()
}, timeout)
}
}