OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Is it possible to have the play event not directly on a video, but on a document?

  • Thread starter Thread starter pileup
  • Start date Start date
P

pileup

Guest
I want to listen to any play event: https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/play_event

From the docs the listener must be attached to a video.

And the following didn't work:

Code:
document.addEventListener("play", (event) => {
    // do something when some video starts playing
});

Because I want to do some generic actions when any video starts playing in the page, so I don't want to attach listener to every video (so to use delegation)

The reason I need to do it is because I have custom controls, and I want to be able to change the buttons (toggle play/pause for example) whenever a video is played/paused, without having the listener on the video itself every time

<p>I want to listen to any <code>play</code> event: <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/play_event" rel="nofollow noreferrer">https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/play_event</a></p>
<p>From the docs the listener must be attached to a video.</p>
<p>And the following didn't work:</p>
<pre><code>document.addEventListener("play", (event) => {
// do something when some video starts playing
});
</code></pre>
<p>Because I want to do some generic actions when any video starts playing in the page, so I don't want to attach listener to every video (so to use delegation)</p>
<p>The reason I need to do it is because I have custom controls, and I want to be able to change the buttons (toggle play/pause for example) whenever a video is played/paused, without having the listener on the video itself every time</p>
 

Latest posts

M
Replies
0
Views
1
Marketerhire
M
E
Replies
0
Views
1
EMAPPLY
E
Top