Moved sync latching logic over to mediaHandler class.
This commit is contained in:
parent
d3aa4b8274
commit
99fa549469
|
|
@ -23,6 +23,9 @@ class mediaHandler{
|
|||
//Set handler type
|
||||
this.type = type
|
||||
|
||||
//Denotes wether a seek call was made by the syncing function
|
||||
this.selfAct = false;
|
||||
|
||||
//Set last received timestamp to 0
|
||||
this.lastTimestamp = 0;
|
||||
|
||||
|
|
@ -69,12 +72,20 @@ class mediaHandler{
|
|||
}
|
||||
|
||||
sync(timestamp = this.lastTimestamp){
|
||||
//Skip sync calls that won't seek so we don't pointlessly throw selfAct
|
||||
if(timestamp != this.video.currentTime){
|
||||
//Set self act flag
|
||||
this.selfAct = true;
|
||||
}
|
||||
}
|
||||
|
||||
reload(){
|
||||
//Get current timestamp
|
||||
const timestamp = this.video.currentTime;
|
||||
|
||||
//Throw self act flag to make sure we don't un-sync the player
|
||||
this.selfAct = true;
|
||||
|
||||
//Load video from source
|
||||
this.video.load();
|
||||
|
||||
|
|
@ -86,7 +97,13 @@ class mediaHandler{
|
|||
}
|
||||
|
||||
end(){
|
||||
//Null out current media
|
||||
this.nowPlaying = null;
|
||||
|
||||
//Throw self act to prevent unlock on video end
|
||||
this.selfAct = true;
|
||||
|
||||
//Destroy the player
|
||||
this.destroyPlayer();
|
||||
}
|
||||
|
||||
|
|
@ -121,6 +138,30 @@ class mediaHandler{
|
|||
setVideoTitle(title){
|
||||
this.player.title.textContent = `Currently Playing: ${title}`;
|
||||
}
|
||||
|
||||
onMetadataLoad(event){
|
||||
//Resize aspect (if locked), since the video doesn't properly report it's resolution until it's been loaded
|
||||
this.client.chatBox.resizeAspect();
|
||||
}
|
||||
|
||||
onPause(event){
|
||||
//If the video was paused out-side of code
|
||||
if(!this.selfAct){
|
||||
this.player.unlockSync();
|
||||
}
|
||||
|
||||
this.selfAct = false;
|
||||
}
|
||||
|
||||
onSeek(event){
|
||||
//If the video was seeked out-side of code
|
||||
if(!this.selfAct){
|
||||
this.player.unlockSync();
|
||||
}
|
||||
|
||||
//reset self act flag
|
||||
this.selfAct = false;
|
||||
}
|
||||
}
|
||||
|
||||
class nullHandler extends mediaHandler{
|
||||
|
|
@ -157,15 +198,16 @@ class nullHandler extends mediaHandler{
|
|||
}
|
||||
}
|
||||
|
||||
//This at first was hard to seperate out as parts of it are used for other handlers because they're based on the <video> tag
|
||||
//Others simply because this was the first actual media handler and there are parts necissary for ALL media handlers, even ones That being said I think I split this up in a way that makes sense :P
|
||||
//Essentially, the base class is enough to make a video tag and handle things every handler does like sync locking
|
||||
//Null is just enough added on to play the static
|
||||
//And the raw file handler adds on everything needed to sync up a raw file
|
||||
class rawFileHandler extends mediaHandler{
|
||||
constructor(client, player, media){
|
||||
//Call derived constructor
|
||||
super(client, player, media, 'raw');
|
||||
|
||||
//Since this media type has no way to tell between events that originate from either the user or code
|
||||
//That's what this boolean is for :P
|
||||
this.selfAct = false;
|
||||
|
||||
//Define listeners
|
||||
this.defineListeners();
|
||||
}
|
||||
|
|
@ -199,56 +241,18 @@ class rawFileHandler extends mediaHandler{
|
|||
}
|
||||
|
||||
sync(timestamp = this.lastTimestamp){
|
||||
//Call derived sync
|
||||
super.sync(timestamp);
|
||||
|
||||
//Skip sync calls that won't seek so we don't pointlessly throw selfAct
|
||||
if(timestamp != this.video.currentTime){
|
||||
//Set self act flag
|
||||
this.selfAct = true;
|
||||
|
||||
//Set current video time based on timestamp received from server
|
||||
this.video.currentTime = timestamp;
|
||||
}
|
||||
}
|
||||
|
||||
reload(){
|
||||
//Throw self act flag to make sure we don't un-sync the player
|
||||
this.selfAct = true;
|
||||
|
||||
//Call derived reload function
|
||||
super.reload();
|
||||
}
|
||||
|
||||
onMetadataLoad(event){
|
||||
//Resize aspect (if locked), since the video doesn't properly report it's resolution until it's been loaded
|
||||
this.client.chatBox.resizeAspect();
|
||||
}
|
||||
|
||||
onPause(event){
|
||||
//If the video was paused out-side of code
|
||||
if(!this.selfAct){
|
||||
this.player.unlockSync();
|
||||
}
|
||||
|
||||
this.selfAct = false;
|
||||
}
|
||||
|
||||
onSeek(event){
|
||||
//If the video was seeked out-side of code
|
||||
if(!this.selfAct){
|
||||
this.player.unlockSync();
|
||||
}
|
||||
|
||||
//reset self act flag
|
||||
this.selfAct = false;
|
||||
}
|
||||
|
||||
getTimestamp(){
|
||||
//Return current timestamp
|
||||
return this.video.currentTime;
|
||||
}
|
||||
|
||||
end(){
|
||||
//Throw self act to prevent unlock on video end
|
||||
this.selfAct = true;
|
||||
super.end();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue