Reputation: 1248
I have an mp4 video that is on my server and I view it in my browser with the HTML player. How can I adjust the audio/video sync with javascript? The audio and video are not two separate files. I want the audio to be something like 200 ms behind the video so that they can line up fine when having Bluetooth headphones that are laggy.
Upvotes: 1
Views: 1284
Reputation:
You try to seperate your audio and then open both; video before 200ms and then the audio...
Then you may use audio like this...
<html>
<body>
<audio id="myAudio">
<source src="AUDIO.ogg" type="audio/ogg">
<source src="AUDIO.mp3" type="audio/mpeg">
</audio>
<p>Click the buttons to play or pause the audio.</p>
<button onclick="playAudio()" type="button">Play Audio</button>
<button onclick="pauseAudio()" type="button">Pause Audio</button>
<script>
var x = document.getElementById("myAudio");
function playAudio() {
x.play();
}
function pauseAudio() {
x.pause();
}
</script>
</body>
</html>
Then try... Or you can: -
<html>
<head>
<title>My Audio</title>
</head>
<body>
<audio src="AUDIO.mp3" id="my_audio" loop="loop"></audio>
<script type="text/javascript">
setTimeout(function(){
document.getElementById("my_audio").play();
console.log('your audio is started just now');
}, 8000)
</script>
</body>
</html>
Upvotes: 2