Skip to content

Instantly share code, notes, and snippets.

@stmoerman
Created June 7, 2018 22:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stmoerman/c7ba7cf9e6ff5b5d8b1d49c4a1d13be2 to your computer and use it in GitHub Desktop.
Save stmoerman/c7ba7cf9e6ff5b5d8b1d49c4a1d13be2 to your computer and use it in GitHub Desktop.
<video id="myvideo" controls muted loop>
<source src="sample_video_no_sound.mp4" type="video/mp4"/>
<audio id="myaudio">
<source src="sound.mp3" type="audio/mpeg"/>
</audio>
</video>
<script>
var myvideo = document.getElementById("myvideo");
var myaudio = document.getElementById("myaudio");
var change_time_state = true;
myvideo.onplay = function(){
myaudio.play();
if(change_time_state){
myaudio.currentTime = myvideo.currentTime;
change_time_state = false;
}
}
myvideo.onpause = function(){
myaudio.pause();
change_time_state = true;
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment