handle play/pause when window is hidden

using `webkitvisibilitychange` event
This commit is contained in:
Mathias Rasmussen
2016-06-10 04:51:14 +02:00
parent bf372029fb
commit 3b832595fe

View File

@@ -91,6 +91,9 @@ function onState (err, _state) {
window.addEventListener('focus', onFocus) window.addEventListener('focus', onFocus)
window.addEventListener('blur', onBlur) window.addEventListener('blur', onBlur)
// ...window visibility state.
document.addEventListener('webkitvisibilitychange', onVisibilityChange)
sound.play('STARTUP') sound.play('STARTUP')
// Done! Ideally we want to get here < 500ms after the user clicks the app // Done! Ideally we want to get here < 500ms after the user clicks the app
@@ -360,6 +363,9 @@ function playPause () {
} else { } else {
pause() pause()
} }
// force rerendering if window is hidden,
// in order to bypass `raf` and play/pause media immediately
if (!state.window.isVisible) render(state)
} }
function jumpToTime (time) { function jumpToTime (time) {
@@ -1296,3 +1302,7 @@ function onBlur () {
state.window.isFocused = false state.window.isFocused = false
update() update()
} }
function onVisibilityChange () {
state.window.isVisible = !document.webkitHidden
}