Seperate audio tracks are now *reasonably* synchronized to their videos. This may need more testing to perfect.
This commit is contained in:
parent
a59b6d0e19
commit
ccb1d91a5b
|
|
@ -401,6 +401,15 @@ class rawFileHandler extends rawFileBase{
|
|||
//Call derived constructor
|
||||
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
|
||||
this.defineListeners();
|
||||
}
|
||||
|
|
@ -428,6 +437,7 @@ class rawFileHandler extends rawFileBase{
|
|||
//Destroy the audio player
|
||||
this.audio.pause();
|
||||
this.audio.remove();
|
||||
clearInterval(this.audioInterval);
|
||||
}
|
||||
|
||||
start(){
|
||||
|
|
@ -461,14 +471,11 @@ class rawFileHandler extends rawFileBase{
|
|||
//play video
|
||||
this.video.play();
|
||||
|
||||
//if we have an audio src
|
||||
/*/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(){
|
||||
|
|
@ -476,22 +483,22 @@ class rawFileHandler extends rawFileBase{
|
|||
this.video.play();
|
||||
|
||||
|
||||
//if we have a seperate audio track
|
||||
/*/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 we have a seperate audio track
|
||||
if(this.audio.src != ""){
|
||||
//Pause it too
|
||||
this.audio.pause();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
sync(timestamp = this.lastTimestamp){
|
||||
|
|
@ -537,6 +544,7 @@ class rawFileHandler extends rawFileBase{
|
|||
this.audio.currentTime = this.video.currentTime;
|
||||
//pause it
|
||||
this.audio.pause();
|
||||
clearInterval(this.audioInterval);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -550,18 +558,38 @@ class rawFileHandler extends rawFileBase{
|
|||
this.audio.currentTime = this.video.currentTime;
|
||||
//pause it
|
||||
this.audio.pause();
|
||||
clearInterval(this.audioInterval);
|
||||
}
|
||||
}
|
||||
|
||||
onPlay(event){
|
||||
//if we have a seperate audio track
|
||||
if(this.audio != "" && this.video != null){
|
||||
//Set audio volume
|
||||
this.audio.volume = this.player.volume;
|
||||
//Set it's timestamp
|
||||
this.audio.currentTime = this.video.currentTime;
|
||||
//pause it
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue