-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#28 Implement feature to keep video and audio in sync
- Loading branch information
Bennett Hollstein
committed
Jul 23, 2021
1 parent
4ad44aa
commit 8f4b7be
Showing
7 changed files
with
85 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import ConfigProvider from "../../shared/configProvider"; | ||
import debug from '../../shared/debug'; | ||
import SilenceSkipper from './SilenceSkipper'; | ||
|
||
/** | ||
* Audio Synchronizer | ||
* This will help to keep Audio and Video in sync on Chromium based browsers | ||
* | ||
* Related: https://github.com/vantezzen/skip-silence/issues/28 | ||
*/ | ||
export default class AudioSync { | ||
// Parent skipper | ||
skipper : SilenceSkipper; | ||
|
||
// Is the loop currently running | ||
isActive = false; | ||
|
||
/** | ||
* Set up the class | ||
* | ||
* @param config Config to use | ||
*/ | ||
constructor(skipper : SilenceSkipper) { | ||
this.skipper = skipper; | ||
this.sync = this.sync.bind(this); | ||
|
||
this.skipper.config.onUpdate(() => { | ||
if (this.skipper.config.get('keep_audio_sync') && !this.isActive) { | ||
// Start the loop | ||
this.sync(); | ||
} | ||
}); | ||
|
||
this.sync(); | ||
} | ||
|
||
/** | ||
* Synchronize the audio and video of the media element | ||
*/ | ||
private sync() { | ||
if (this.skipper.config.get('keep_audio_sync')) { | ||
this.isActive = true; | ||
this.skipper.element.currentTime = this.skipper.element.currentTime; | ||
debug("AudioSync: Synced audio"); | ||
|
||
setTimeout(this.sync, 5000); | ||
} else { | ||
debug('AudioSync: Stopping because option was disabled'); | ||
|
||
this.isActive = false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters