muxinc / media-chrome

Custom elements (web components) for making audio and video player controls that look great in your website or app.
https://media-chrome.org
MIT License
1.11k stars 56 forks source link

How to determine if a media is playing? #929

Closed 2Pacalypse- closed 1 week ago

2Pacalypse- commented 1 week ago

I'm sorry for a silly question and I'm not sure if I'm missing something, but it seems like it's needlessly hard to determine if the media is currently playing?

There is a mediapaused attribute that's set when the media is paused, obviously. So the naïve approach to determine if the media is playing to do !mediaElem.hasAttribute('mediapaused'). However, this also returns true sometimes during code initialization, I think?. So it seems like I have to combine the mediapaused attribute with also checking if the mediacurrenttime is larger than 0 or something.

I feel like just having a mediaplaying attribute might simplify things a bit.

luwes commented 1 week ago

Thanks for the feedback!

The best source of truth is still the slotted media element, I recommend using that for determining playing state. With the media.paused and play, playing and pause events you should have everything you need.

We purposely built Media Chrome like this, it doesn't try to be a full player. Hope this helps, let me know if it doesn't make sense. Cheers!