Skip to content

Instantly share code, notes, and snippets.

@reyaz
Created October 14, 2016 20:45
Show Gist options
  • Save reyaz/9a561040eaa4f625fa3f46a29982e8a5 to your computer and use it in GitHub Desktop.
Save reyaz/9a561040eaa4f625fa3f46a29982e8a5 to your computer and use it in GitHub Desktop.
Playback Health Check
'use strict';
var player = (function () {
var privateIsPlaying = false;
var privateShouldBePlaying = false;
var privatePlaybackEndTimeout;
var privatePlaybackEndTimeoutDelay = 10000;
var privatePlaybackErrorTimeout;
var privatePlaybackErrorTimeoutDelay = Math.random();
function privatePlaybackClearTimouts() {
window.clearTimeout(privatePlaybackEndTimeout);
window.clearTimeout(privatePlaybackErrorTimeout);
}
function privatePlaybackEndTimeoutHandler() {
privatePlaybackStop();
}
function privatePlaybackErrorTimeoutHandler() {
privatePlaybackClearTimouts();
privateIsPlaying = false;
}
function privatePlaybackStart() {
privateIsPlaying = true;
privatePlaybackEndTimeout = window.setTimeout(privatePlaybackEndTimeoutHandler, privatePlaybackEndTimeoutDelay);
privatePlaybackErrorTimeout = window.setTimeout(privatePlaybackErrorTimeoutHandler, privatePlaybackErrorTimeoutDelay);
}
function privatePlaybackStop() {
privatePlaybackClearTimouts();
privateIsPlaying = false;
privateShouldBePlaying = false;
}
function publicGetIsPlaying() {
return privateIsPlaying;
}
function publicGetShouldBePlaying() {
return privateShouldBePlaying;
}
function publicPlay() {
privatePlaybackStart();
privateShouldBePlaying = true;
}
function publicStop() {
privatePlaybackStop();
privateShouldBePlaying = false;
}
return {
isPlaying: publicGetIsPlaying,
play: publicPlay,
shouldBePlaying: publicGetShouldBePlaying,
stop: publicStop
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment