fix(playback): resolve race condition to prevent OSD takeover#429
Conversation
RadicalMuffinMan
left a comment
There was a problem hiding this comment.
A getter like get playingStream => _mergeWithStale(...) re-runs its right-hand side every single time something reads playingStream. So each read builds a fresh StreamController and wires up its own two subscriptions to the player. Today the code reads it only once, so you never notice. But the moment two places read playingStream, you end up with two separate controllers both hooked into the same player, and the spare one just sits there listening forever because nothing ever tears it down.
late final is Dart's way of saying "build this once, then keep handing back the same thing." The first time the field gets read, Dart runs the initializer (the _mergeWithStale(...) call), saves the result, and from then on every read returns that saved value. So no matter how many times anyone touches playingStream, the stream is built a single time.
The getter now just returns that saved field (get playingStream => _playingStream), so nothing changes for the people using it. Callers still write backend.playingStream.listen(...) exactly like before.
…ing streams - Introduce _mergeWithStale helper to combine the native player stream with playlist updates. - Ensure playingStream and bufferingStream correctly re-evaluate and emit their values once the media loads and _isStale becomes false. - Resolves the play/pause button state getting stuck on the Play icon and prevents the OSD controls from getting stuck on screen.
|
Fixes incorporated, thanks! |
resolve race condition to prevent OSD takeover
Summary
Resolves a race condition on desktop platforms using
media_kitwhere the play/pause button state gets stuck on the Play icon and the OSD controls fail to auto-hide when video playback begins.Related Issues
None - bug found during playback testing
Type of Change
Changes Made
_mergeWithStale<T>helper method inMediaKitPlayerBackendwhich merges the underlying streams with_player.stream.playlistevents.playingStreamandbufferingStreamgetters to utilize this helper to ensure they are re-evaluated and re-emitted once_isStalebecomesfalsewhen media loads.Platform
Testing
Describe how this change was tested.
Test Steps
Checklist