Skip to content

feat(core): report system video pauses - #278

Draft
houko wants to merge 7 commits into
mainfrom
feat/video-system-pause
Draft

houko wants to merge 7 commits into
mainfrom
feat/video-system-pause

Conversation

@houko

@houko houko commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #276

What changed

core.Video reports what the platform does to playback by itself: OnPause(VideoPauseReason) when its built-in controls, an interruption or a lost audio output pause it, and OnPlay when the controls or the system play it. TSX gets onPause({ reason }) and onPlay, and nsgotest gets PauseVideo and PlayVideo to report them headless.

Paused applies when it changes and when a source opens. Between changes the platform's play state holds: a pause from the controls or the system is not undone by an unrelated prop change such as the volume, and a play from the controls while Paused is true is not paused again. An app that shows its own play state follows the events in Paused, which takes the video back. When a transient interruption ends and the system allows it (iOS's ShouldResume, Android's focus coming back), a video still paused by it plays on and reports OnPlay; a permanent focus loss and a lost output leave it paused.

  • Apple: apple/videoplay.go keeps who holds the play state and is unit tested. The backend follows AVPlayerRateDidChangeNotification (with its reason key for interruptions and backgrounding), iOS's interruption and route-change notifications, and ignores the rate drop at the item's end, which OnEnd reports. macOS reports its AVPlayerView controls through the same path.
  • Android: VideoNode holds a MediaController or audio-focus pause without touching the app's paused, keeps the focus request through a transient loss so it can play on, listens for ACTION_AUDIO_BECOMING_NOISY only while playing unmuted, and reports the controls' play. classes.dex/classes.jar rebuilt.
  • The two events share the driver kinds of EventImageInfo and EventMenuClosed, as EventMask has no free bit; the core routes them by view ID, and a removed video's report goes nowhere.
  • Windows' drawn bar, GTK's controls and the browser's controls do not report yet; that and the iPhone check are recorded in the roadmap.

Verification

  • go build ./...; Windows, Linux, wasm builds and Android/iOS vets of the touched packages; go tool nsgo check -target all
  • go tool nsgo test for ./core, ./internal/driver, ./internal/platform/apple, ./internal/platform/android, ./tsx, ./nsgotest, and -run 'Layer|Skills|Doc' .
  • macOS: TestVideoReportsWhatItsPlayerDidByItself runs a real AVPlayer in a window, pauses and plays it as its controls do, and checks the pause holds through a volume change, the app's own pause and play are not reported, and the end reports no pause. It fails on the PR's first version.
  • Pixel 3 XL (Android 12), probe app with Controls and AudioSession playback: controls pause reported once and held through a volume change; controls play reported; a timer alarm's transient focus paused it (interruption) and stopping the alarm played it on (OnPlay); after the app followed a pause with Paused the alarm's end did not resume it; another app taking the focus for good paused it and it stayed paused; the app's own pause and play were not reported.
  • A lost output (unplugged headphones) pauses only a video that is not Muted, on iOS and Android: a muted video, such as a looping background clip, has nothing to stop, and would otherwise stay paused until Paused changed.
  • Not checked on a device: unplugged headphones on Android, and everything on iOS (no usable iPhone). The last commit, which limits the lost-output pause to unmuted videos, has not run on the Pixel yet.

@github-actions github-actions Bot added size/M enhancement New feature or request documentation Improvements or additions to documentation macOS iOS Android core conflict Conflicts with the base branch; resolve it first labels Nov 15, 2026
… rate change

AVPlayer posts AVPlayerRateDidChangeNotification on the main queue before pause and setRate: return, so the backend's own changes were reported as the controls'. A macOS test pauses and plays a playing video's AVPlayer as its controls do and checks what the app hears.
@houko
houko force-pushed the feat/video-system-pause branch from ffd5609 to 9298add Compare November 16, 2026 04:34
@github-actions github-actions Bot added size/L tsx and removed size/M conflict Conflicts with the base branch; resolve it first labels Nov 16, 2026
A muted video, such as a looping background clip, has nothing to stop when headphones are unplugged, yet both backends paused it and held the pause until Paused changed, so it stayed still. Android now listens for ACTION_AUDIO_BECOMING_NOISY only while the video plays unmuted, and iOS pauses for a lost route only an unmuted video. The videos doc says so.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Android core documentation Improvements or additions to documentation enhancement New feature or request iOS macOS size/L tsx

Projects

None yet

Development

Successfully merging this pull request may close these issues.

core: Video cannot tell the app that the system paused it

1 participant