Mi función setTimeout() no se repite después de que se ejecuta la inicial. Se ejecuta inicialmente en "Window.onload", pero el segundo setTimeout() dentro de la función "myHandler" no se ejecuta
área problemática: tiempo de espera de var;
window.onload = function(){ timeout = setTimeout(myHandler, 5000); }; function myHandler() { i++; timeout = setTimeout(myHandler, 10000) }código completo en HTML:
<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; var timeout; window.onload = function(){ timeout = setTimeout(myHandler, 5000); }; function myHandler() { alert('run') i++; if (i == (videoCount - 1)) { i = 0; videoPlay(i); } else { videoPlay(i); } timeout = setTimeout(myHandler, 10000) } function videoPlay(videoNum) { document.getElementById("myVideo").setAttribute("src", `${videoSource[videoNum]}&parent=localhost&autoplay=true&muted=false`); document.getElementById("myVideo").load(); document.getElementById("myVideo").play(); } videoPlay(0); // play the video </script> </body> </html>Ejecuté el código localmente y obtuve algunos errores en la función videoPlay. Creo que no hay nada malo en setTimeout, pero cuando el javascript falla, la función no se vuelve a ejecutar. Intente comentar las llamadas de videoPlay y se ejecutará el código.
Considere usar setInterval en lugar de setTimeout. Y no necesita llamar a videoPlay on if y else, puede rehacer eso para
if (i == videoCount - 1) i = 0 videoPlay(i)Resolví mi propio problema como resulta:
document.getElementById("myVideo").load(); document.getElementById("myVideo").play();no son funciones con iframe que no estaba ejecutando el resto de mi código.
Gracias a todos por su ayuda y aporte.