Created
May 26, 2017 13:33
-
-
Save vgrafe/a094a8dd3865624b371cd1719efe0101 to your computer and use it in GitHub Desktop.
excerpt of the videoplayer watchdog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Setting the watchdog is done with the following. the app uses ReactJS as a framework. | |
// this is just the relevant part of the code. | |
componentDidMount() { | |
this.watchdog = setInterval(this.checkPlayerHealth, 500); | |
} | |
checkPlayerHealth = () => { | |
const delay = this.video.currentTime - this.state.debug.lastCheck; | |
if (!this.video.paused && delay < 0.1 // prob freezing | |
&& new Date().getTime() - this.state.debug.lastUserAction > 200 // not triggered by user action | |
&& new Date().getTime() - this.state.debug.lastRevival > 5000 // not already being revived | |
) { | |
this.revivePlayer(); | |
} | |
} | |
revivePlayer = () => { | |
// option 1, too visible | |
this.video.currentTime = this.video.currentTime + 10; | |
setTimeout(() => { | |
this.video.currentTime = this.video.currentTime - 10; | |
}, 30); | |
// option 2 that mimics seek() with same time - does not work | |
this.video.currentTime = this.video.currentTime; | |
// option 3, not working | |
this.video.pause(); | |
setTimeout(() => { | |
this.video.play(); | |
}, 30); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment