revert _playing flag: playing event fires on every resume

Tested in Chrome (headless, --autoplay-policy=no-user-gesture-required):
playing fires on every pause-to-play transition, not just the first
time. The _playing flag was incorrectly suppressing this. Removed it
and updated tests to match verified Chrome behavior.
This commit is contained in:
egrs
2026-02-18 10:49:27 +01:00
parent 830eb74725
commit 7675feca91
2 changed files with 7 additions and 12 deletions

View File

@@ -76,21 +76,21 @@
audio.pause();
testing.expectEqual('play,playing,pause', events.join(','));
// Third play: resume from pause, fires play only (not playing)
// Third play: resume from pause, fires play + playing (verified in Chrome)
audio.play();
testing.expectEqual('play,playing,pause,play', events.join(','));
testing.expectEqual('play,playing,pause,play,playing', events.join(','));
// Pause again
audio.pause();
testing.expectEqual('play,playing,pause,play,pause', events.join(','));
testing.expectEqual('play,playing,pause,play,playing,pause', events.join(','));
// Load: resets state, fires emptied
audio.load();
testing.expectEqual('play,playing,pause,play,pause,emptied', events.join(','));
testing.expectEqual('play,playing,pause,play,playing,pause,emptied', events.join(','));
// Play after load: fires play + playing again (fresh start)
// Play after load: fires play + playing
audio.play();
testing.expectEqual('play,playing,pause,play,pause,emptied,play,playing', events.join(','));
testing.expectEqual('play,playing,pause,play,playing,pause,emptied,play,playing', events.join(','));
}
</script>

View File

@@ -61,7 +61,6 @@ _playback_rate: f64 = 1.0,
_ready_state: ReadyState = .HAVE_NOTHING,
_network_state: NetworkState = .NETWORK_EMPTY,
_error: ?*MediaError = null,
_playing: bool = false,
pub fn asElement(self: *Media) *Element {
return self._proto._proto;
@@ -145,12 +144,9 @@ pub fn play(self: *Media, page: *Page) !void {
self._network_state = .NETWORK_IDLE;
if (was_paused) {
try self.dispatchEvent("play", page);
if (!self._playing) {
self._playing = true;
try self.dispatchEvent("playing", page);
}
}
}
pub fn pause(self: *Media, page: *Page) !void {
if (!self._paused) {
@@ -161,7 +157,6 @@ pub fn pause(self: *Media, page: *Page) !void {
pub fn load(self: *Media, page: *Page) !void {
self._paused = true;
self._playing = false;
self._current_time = 0;
self._ready_state = .HAVE_NOTHING;
self._network_state = .NETWORK_LOADING;