When playing a live audio stream, like web radio, through <audio>
or Audio()
, the pause event can fire in (at least) three ways:
- user clicks on the pause button (with
<audio controls>
) - user clicks the browsers global audio controls
- iOS: Control Center
- Android: browser's notification drawer (at least Chrome, Opera, Firefox)
- Desktop: Media Session API controls, but uninitialized, without explicit
setActionHandler
(might be hidden behind a flag as of now)
- a buffer underrun caused by various network conditions
Is it possible to distinguish between 1/2 and 3?
- Ideally, there would be an event property like
isTrusted
, which I am missing - I have tried to guess, looking esp. at
readyState
andnetworkState
, but both are very inconclusive, especially across browsers (e.g. the interpretation/semantics ofHAVE_FUTURE_DATA
vsHAVE_ENOUGH_DATA
) - I have shied away from making a "decaying state machine", juggling other events. A buffer underrun is often preceded by
stalled
events, and sometimes followed byended
events. A cross-browser implementation seems crazy complex and the danger of false positives very high.
Am I out of luck until Media Session lands everywhere?
Note: this question looks like a solution, but unfortunately isn't -- browsers handle live streams' "ends" differently and inconsistently.