Home > Net >  syncing audio and video on seek
syncing audio and video on seek

Time:09-11

I am using a different audio file for a video. I currently have them play together on click and same for pause. The problem is seeking how can I sync both audio and video when user seeks the video. Thanks in advance.

var myvideo = document.getElementById("myvideo");
var myaudio = document.getElementById("myaudio");
myvideo.onplay = function() {
  myaudio.play();
}
myvideo.onpause = function() {
  myaudio.pause();
}
video {
  width: 100vw;
  height: 100vh;
}
<video id="myvideo" controls muted>
<source src="https://yewtu.be/latest_version?id=ZqyAI1L_Seo&itag=399" type="video/mp4" />
<audio id="myaudio" controls>
  <source src="https://yewtu.be/latest_version?id=ZqyAI1L_Seo&itag=251" type="audio/webm">
</audio>
</video>

CodePudding user response:

Couldn't fine a browser-only solution.

You can create a backend service to combine the streams into one. I.E. by using this and consume it from browser.

  • Related