Menu

Stop Faking “Playing” State When Video play() Is Rejected
📰

Stop Faking “Playing” State When Video play() Is Rejected

DEV Community: html·jojo_willnn_·3 days ago
#gGfLHxWt
#devto2#devto#dev#playback#play
Long article (348 words) — no AI summary yet.
Reading 0:00
15s threshold

An editor can load a video successfully and still fail to play it. If your UI flips to “playing” the moment play() is invoked, the controls can easily describe a playback state the browser never actually entered.

Wait for the playback outcome

HTMLMediaElement.play() returns a Promise. Handle both resolution and rejection cleanly, and always keep a clear, accessible way for the user to trigger playback manually. The MDN HTMLMediaElement.play() reference outlines the common reasons—such as autoplay policies or media constraints—why script-initiated playback may be rejected.

This gets trickier in a background remover video workflow where the original clip and the processed output live in separate media elements. Even if one preview starts playing without issue, that does not guarantee the companion element started too.

Make the button describe reality

Avoid optimistic UI updates that switch the button label to “Pause” or “Playing” without rolling back on failure.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.