Skip to main content

## player_background_action

# Function player_background_action

Source

    pub async fn player_background_action(
        player: State<'_, PlayerStateWrapper>,
        background_audio_armed: bool,
        in_picture_in_picture: bool,
    ) -> Result<BackgroundAction, String>

Expand description

Exit background-audio mode: stop the native audio player and return its final position so the frontend can reload the WebView `<video>` there (UR-040).

Returns the position in seconds. The sleep timer is intentionally left untouched — if it fired while backgrounded, playback is already stopped and this simply reports the last position.

What playback should do now that the app is no longer visible.

The caller supplies only what it alone knows – whether the per-player toggle is armed, and whether Android put the window into picture-in-picture. Everything else (what is playing, and therefore whether there is a picture to lose) is read here, because it is domain state.

The rule itself is in `player::background_policy`; this command is the wire. Returning `KeepPlaying` for an empty queue is deliberate: with nothing playing there is nothing to pause, and an error would make the frontend handle a case that is not a failure.

TRACES: UR-040, UR-041 | DR-225 | UT-212