Merge pull request #632 from mathiasvr/patch

handle play/pause when window is hidden
This commit is contained in:
Feross Aboukhadijeh
2016-06-10 20:23:58 -07:00
committed by GitHub

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
}