1

I would like to know how can I check if the site is playing the audio. I have tried this, but it doesnt seem to work for me: HTML:

<iframe width="500px" height="300px" id="player" src="https://www.youtube.com/embed/gPDcwjJ8pLg"></iframe>

And my JS:

var myAudio = document.getElementById('player');

myAudio.addEventListener("ended", function(){
  myAudio.currentTime = 0;
  alert("ended");
});

Thanks for any advice.

Adam Šulc
  • 482
  • 3
  • 20
  • Your YouTube link is an ` – Obsidian Age Jan 31 '18 at 19:23
  • 2
    Possible duplicate of [How to detect when a youtube video finishes playing?](https://stackoverflow.com/questions/7853904/how-to-detect-when-a-youtube-video-finishes-playing) – Shibin Raju Mathew Jan 31 '18 at 19:24
  • No, I want to check if the site is playing any audio, not if the audio finishes playing. – Adam Šulc Jan 31 '18 at 19:28
  • @ObsidianAge ok, I understand that now. So do you have any idea how can i check if the iframe audio is playing on the site? – Adam Šulc Jan 31 '18 at 19:29
  • Rename your questions as `any idea how can i check if the iframe audio is playing` this is interesting. – NVRM Jan 31 '18 at 19:35

1 Answers1

0

See https://developers.google.com/youtube/iframe_api_reference The IFrame player API lets you embed a YouTube video player on your website and control the player using JavaScript.

  • Good, but I would rather like to have iframe as HTML element and not as getting called by the API. Can I control the iframe element just by the javascript? – Adam Šulc Jan 31 '18 at 19:34