From a59b6d0e192d21de69f66446947a1e3b129cf809 Mon Sep 17 00:00:00 2001 From: rainbow napkin Date: Fri, 31 Oct 2025 20:22:17 -0400 Subject: [PATCH] Started work on syncronizing seperated audio and video tracks into back into one player. --- www/js/channel/mediaHandler.js | 124 ++++++++++++++++++++++++++++++++- www/js/channel/player.js | 4 +- 2 files changed, 124 insertions(+), 4 deletions(-) diff --git a/www/js/channel/mediaHandler.js b/www/js/channel/mediaHandler.js index f15ef89..0eb0d4e 100644 --- a/www/js/channel/mediaHandler.js +++ b/www/js/channel/mediaHandler.js @@ -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(); - //Set video - this.video.src = this.nowPlaying.rawLink; + //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 = 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(); + } + } } /** diff --git a/www/js/channel/player.js b/www/js/channel/player.js index 568886f..612d946 100644 --- a/www/js/channel/player.js +++ b/www/js/channel/player.js @@ -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`); } }