Skip to content

Instantly share code, notes, and snippets.

@vgrafe
Created May 26, 2017 13:33
Show Gist options
  • Save vgrafe/a094a8dd3865624b371cd1719efe0101 to your computer and use it in GitHub Desktop.
Save vgrafe/a094a8dd3865624b371cd1719efe0101 to your computer and use it in GitHub Desktop.
excerpt of the videoplayer watchdog
// 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