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.
This commit is contained in:
egrs
2026-02-17 16:10:49 +01:00
parent 0a58918f47
commit 1b71d1e46d
2 changed files with 6 additions and 6 deletions

View File

@@ -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(','));
}
</script>

View File

@@ -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);
}
}
pub fn pause(self: *Media, page: *Page) !void {