var curtime = document.querySelector('#curtime') var starttime = "11:57" var stoptime = "11:58" var timetime = moment().format("HH:mm"); var video = document.querySelector("#ytplayer") setInterval(function(){ var currenttime = moment().format("HH:mm:ss"); curtime.textContent = currenttime; }); function checktime (timetime){ if (timetime = starttime){ video.src = 'https://www.youtube.com/embed/Dx5qFachd3A?autoplay=1' } if (timetime = stoptime){ video.src = '' } } <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" href="./assets/CSS/style.css"> <title>Music</title> </head> <body> <header> <div class="time"> <span id="curtime"></span> </div> </header> <main> <section> <iframe id="ytplayer" type="text/html" width="720" height="405" src="" frameborder="0" allowfullscreen></iframe> </section> </main> </body> <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script> <script src="./assets/JS/main.js"></script> </html>He estado tratando de crear una aplicación para restaurantes donde los dueños de los restaurantes pueden abrir la página web, establecer una hora de inicio y una hora de finalización y agregar una URL de youtube y la página web iniciará y detendrá automáticamente la música en el momento proporcionado.
Intenté usar .play() y .pause() pero eso no funcionó. A cambio, obtuve .play() y .pause() no es una función, así que opté por el enfoque .src. El enfoque .src funciona con el botón pero no con una función 'si'
Cualquier persona con ideas será muy apreciada.