Seperate audio tracks are now *reasonably* synchronized to their videos. This may need more testing to perfect.

This commit is contained in:
rainbow napkin 2025-11-01 07:10:40 -04:00
parent a59b6d0e19
commit ccb1d91a5b

View file

@ -401,6 +401,15 @@ class rawFileHandler extends rawFileBase{
//Call derived constructor //Call derived constructor
super(client, player, media, 'raw'); super(client, player, media, 'raw');
//Re-sync audio every .1 seconds
this.audioSyncDelta = 1000;
//Set audio sync tolerance to .3
this.audioSyncTolerance = .3;
//Create value to hold last calculated difference between audio and video timestamp
this.lastAudioDelta = 0;
//Define listeners //Define listeners
this.defineListeners(); this.defineListeners();
} }
@ -428,6 +437,7 @@ class rawFileHandler extends rawFileBase{
//Destroy the audio player //Destroy the audio player
this.audio.pause(); this.audio.pause();
this.audio.remove(); this.audio.remove();
clearInterval(this.audioInterval);
} }
start(){ start(){
@ -461,14 +471,11 @@ class rawFileHandler extends rawFileBase{
//play video //play video
this.video.play(); this.video.play();
//if we have an audio src /*/if we have an audio src
if(this.audio.src != ""){ if(this.audio.src != ""){
//Set audio volume
this.audio.volume = this.player.volume;
//Play it too //Play it too
this.audio.play(); this.audio.play();
} }*/
} }
play(){ play(){
@ -476,22 +483,22 @@ class rawFileHandler extends rawFileBase{
this.video.play(); this.video.play();
//if we have a seperate audio track /*/if we have a seperate audio track
if(this.audio.src != ""){ if(this.audio.src != ""){
//Play it too //Play it too
this.audio.play(); this.audio.play();
} }*/
} }
pause(){ pause(){
//pause video //pause video
this.video.pause(); this.video.pause();
//if we have a seperate audio track /*/if we have a seperate audio track
if(this.audio.src != ""){ if(this.audio.src != ""){
//Pause it too //Pause it too
this.audio.pause(); this.audio.pause();
} }*/
} }
sync(timestamp = this.lastTimestamp){ sync(timestamp = this.lastTimestamp){
@ -537,6 +544,7 @@ class rawFileHandler extends rawFileBase{
this.audio.currentTime = this.video.currentTime; this.audio.currentTime = this.video.currentTime;
//pause it //pause it
this.audio.pause(); this.audio.pause();
clearInterval(this.audioInterval);
} }
} }
@ -550,18 +558,38 @@ class rawFileHandler extends rawFileBase{
this.audio.currentTime = this.video.currentTime; this.audio.currentTime = this.video.currentTime;
//pause it //pause it
this.audio.pause(); this.audio.pause();
clearInterval(this.audioInterval);
} }
} }
onPlay(event){ onPlay(event){
//if we have a seperate audio track //if we have a seperate audio track
if(this.audio != "" && this.video != null){ if(this.audio != "" && this.video != null){
//Set audio volume
this.audio.volume = this.player.volume;
//Set it's timestamp //Set it's timestamp
this.audio.currentTime = this.video.currentTime; this.audio.currentTime = this.video.currentTime;
//pause it //pause it
this.audio.play(); this.audio.play();
this.audioInterval = setInterval(this.syncAudio.bind(this), this.audioSyncDelta);
} }
} }
syncAudio(){
//get current audi odelta
const audioDelta = this.video.currentTime - this.audio.currentTime;
//If the audio is out of sync enough that someone would notice
if(Math.abs(audioDelta) > this.audioSyncTolerance){
//Set audio volume
this.audio.volume = this.player.volume;
//Re-sync the audio
this.audio.currentTime = this.video.currentTime + audioDelta;
}
//Set last audio delta
this.lastAudioDelta = audioDelta;
}
} }
/** /**