From 1b71d1e46d3c09fb828f81a22da321101af83675 Mon Sep 17 00:00:00 2001 From: egrs Date: Tue, 17 Feb 2026 16:10:49 +0100 Subject: [PATCH] fix playing event: only dispatch on paused-to-playing transition Per MDN, playing fires "after playback is first started, and whenever it is restarted." A second play() while already playing should be a no-op. Both play and playing now only fire on the paused -> playing transition. --- src/browser/tests/element/html/media.html | 10 +++++----- src/browser/webapi/element/html/Media.zig | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/browser/tests/element/html/media.html b/src/browser/tests/element/html/media.html index 80885c6e..ce62ed86 100644 --- a/src/browser/tests/element/html/media.html +++ b/src/browser/tests/element/html/media.html @@ -64,21 +64,21 @@ audio.play(); testing.expectEqual('play,playing', events.join(',')); - // Second play: already playing, fires only playing (not play) + // Second play: already playing, no events audio.play(); - testing.expectEqual('play,playing,playing', events.join(',')); + testing.expectEqual('play,playing', events.join(',')); // Pause: playing -> paused, fires pause audio.pause(); - testing.expectEqual('play,playing,playing,pause', events.join(',')); + testing.expectEqual('play,playing,pause', events.join(',')); // Second pause: already paused, no event audio.pause(); - testing.expectEqual('play,playing,playing,pause', events.join(',')); + testing.expectEqual('play,playing,pause', events.join(',')); // Load: fires emptied audio.load(); - testing.expectEqual('play,playing,playing,pause,emptied', events.join(',')); + testing.expectEqual('play,playing,pause,emptied', events.join(',')); } diff --git a/src/browser/webapi/element/html/Media.zig b/src/browser/webapi/element/html/Media.zig index f5437844..ca9f6088 100644 --- a/src/browser/webapi/element/html/Media.zig +++ b/src/browser/webapi/element/html/Media.zig @@ -144,8 +144,8 @@ pub fn play(self: *Media, page: *Page) !void { self._network_state = .NETWORK_IDLE; if (was_paused) { try self.dispatchEvent("play", page); + try self.dispatchEvent("playing", page); } - try self.dispatchEvent("playing", page); } pub fn pause(self: *Media, page: *Page) !void {