2.0.0 • Published 3 years ago
is-media-playing v2.0.0
🎧 is-media-playing
determine if an HTML MediaElement is currently playing
There is not a specific attribute that will reveal whether a MediaElement is currently playing.
However, you can deduce this from the state of the other attributes. If all of these are true:
currentTime
> 0paused
is falseended
is falsereadyState
doesn't indicate media stopped due to errors
then the MediaElement is currently playing.
based on this great stackoverflow answer:
usage
import isPlaying from 'is-media-playing'
const a = new Audio('/audio/elevator.mp3') // this could also be a video element
a.play()
// wait a while...
const result = isPlaying(a) // result === true if playing, false otherwise