I am trying to create a series of clips in an iframe in HTML. since twitch’s API does not have its own event handler I tried to create my own using HTML but it does not seem to be working.
I attemted to use “.addEventListener(‘ended’, handler())” but once the first video ends it does not run the “myHandler()” function. But strangely it does run “myHandler()” on the first load of the page.
Is there a solution to this issue?
<html>
<body>
<iframe id="myVideo" allowfullscreen="true" height="720"
width="1280"></iframe>
<script type="text/javascript">
var videoSource = new Array();
videoSource[0] = 'xxx';
videoSource[1] = 'xxx';
var i = 0;
var videoCount = videoSource.length;
function videoPlay(videoNum) {
document.getElementById("myVideo").setAttribute("src", `${videoSource[videoNum]}&parent=localhost&autoplay=true&muted=false`);
document.getElementById("myVideo").load();
document.getElementById("myVideo").play();
}
document.getElementById('myVideo').addEventListener('ended', myHandler);
videoPlay(0);
function myHandler() {
alert('complete')
i++;
videoPlay(i);
}
</script>
</body>
</html>