Started work on syncronizing seperated audio and video tracks into back into one player.

This commit is contained in:
rainbow napkin 2025-10-31 20:22:17 -04:00
parent e0832c2c1f
commit a59b6d0e19
2 changed files with 124 additions and 4 deletions

View file

@ -328,6 +328,18 @@ class rawFileBase extends mediaHandler{
//Pull volume from video
this.player.volume = this.video.volume;
}
onSeek(event){
super.onSeek(event);
}
onBuffer(event){
super.onBuffer(event);
}
onPause(event){
super.onPause(event);
}
}
/**
@ -397,17 +409,48 @@ class rawFileHandler extends rawFileBase{
//Run derived method
super.defineListeners();
this.video.addEventListener('playing', this.onPlay.bind(this));
this.video.addEventListener('pause', this.onPause.bind(this));
this.video.addEventListener('seeked', this.onSeek.bind(this));
this.video.addEventListener('waiting', this.onBuffer.bind(this));
}
buildPlayer(){
super.buildPlayer();
this.audio = new Audio();
}
destroyPlayer(){
//Call derived method
super.destroyPlayer();
//Destroy the audio player
this.audio.pause();
this.audio.remove();
}
start(){
//Call derived start
super.start();
//Just pull the combo source by default
const combo = this.nowPlaying.rawLink.combo[0]
//Check if the combo source is null
if(combo != null){
//Set video
this.video.src = this.nowPlaying.rawLink;
this.video.src = combo[1];
}else{
//Pull video only link
const video = this.nowPlaying.rawLink.video[0]
const audio = this.nowPlaying.rawLink.audio[0];
//Set video source
this.video.src = video[1];
this.audio.src = audio[1];
}
//Set video volume
this.video.volume = this.player.volume;
@ -417,14 +460,38 @@ class rawFileHandler extends rawFileBase{
//play video
this.video.play();
//if we have an audio src
if(this.audio.src != ""){
//Set audio volume
this.audio.volume = this.player.volume;
//Play it too
this.audio.play();
}
}
play(){
//play video
this.video.play();
//if we have a seperate audio track
if(this.audio.src != ""){
//Play it too
this.audio.play();
}
}
pause(){
//pause video
this.video.pause();
//if we have a seperate audio track
if(this.audio.src != ""){
//Pause it too
this.audio.pause();
}
}
sync(timestamp = this.lastTimestamp){
@ -436,12 +503,65 @@ class rawFileHandler extends rawFileBase{
//Set current video time based on timestamp received from server
this.video.currentTime = timestamp;
}
//if we have a seperate audio track
if(this.audio != ""){
//Re-sync it to the video, regardless if we synced video
this.audio.currentTime = this.video.currentTime;
}
}
getTimestamp(){
//Return current timestamp
return this.video.currentTime;
}
onSeek(event){
//Call derived event
super.onSeek(event);
//if we have a seperate audio track
if(this.audio != "" && this.video != null){
//Set it's timestamp too
this.audio.currentTime = this.video.currentTime;
}
}
onBuffer(event){
//Call derived event
super.onBuffer(event);
//if we have a seperate audio track
if(this.audio != "" && this.video != null){
//Set it's timestamp
this.audio.currentTime = this.video.currentTime;
//pause it
this.audio.pause();
}
}
onPause(event){
//Call derived event
super.onPause(event);
//if we have a seperate audio track
if(this.audio != "" && this.video != null){
//Set it's timestamp
this.audio.currentTime = this.video.currentTime;
//pause it
this.audio.pause();
}
}
onPlay(event){
//if we have a seperate audio track
if(this.audio != "" && this.video != null){
//Set it's timestamp
this.audio.currentTime = this.video.currentTime;
//pause it
this.audio.play();
}
}
}
/**

View file

@ -195,12 +195,12 @@ class player{
//If we're running a source from IA
if(data.media.type == 'ia'){
//Replace specified CDN with generic URL, in-case of hard reload
data.media.rawLink = data.media.rawLink.replace(/^https(.*)archive\.org(.*)items/g, "https://archive.org/download")
//data.media.rawLink = data.media.rawLink.replace(/^https(.*)archive\.org(.*)items/g, "https://archive.org/download")
//If we have an IA source and a custom IA CDN Server set
if(data.media.type == 'ia' && localStorage.getItem("IACDN") != ""){
//Generate and set new link
data.media.rawLink = data.media.rawLink.replace("https://archive.org/download", `https://${localStorage.getItem("IACDN")}.archive.org/0/items`);
//data.media.rawLink = data.media.rawLink.replace("https://archive.org/download", `https://${localStorage.getItem("IACDN")}.archive.org/0/items`);
}
}