Trying to get a trailer looped until the user clicks somewhere on the screen after which the lecture video is supposed to play once and then revert to the trailer. Managed to find a similar question here on StackOverflow, unfortunately, I'm unable to get it to fully work. The trailer loops and when I click on the button the lecture video plays but does not start the trailer video and instead just loops the lecture video.
What am I doing wrong here?
<video id="mp4Source" autoplay loop controls width="100%" src="/assets/trailer.mp4" >
</video>
<button type="button" name="button" onclick="playLectureVid()"> Play Lecture Vid</button>
function playLectureVid(){
var video = document.getElementById("mp4Source");
video.src = '/assets/lecture.mp4';
video.load();
video.play();
video.addEventListener("ended", function(e) {
e.currentTarget.removeEventListener(e.type, handler);
video.src = '/assets/trailer.mp4';
video.load();
video.play();
});
}