fix(player): let the background-audio toggle govern backgrounding again
🏗️ Build and Test JellyTau / Run Tests (push) Successful in 18m44s
🏗️ Build and Test JellyTau / Supply Chain (push) Failing after 49s
Publish Documentation / Build & publish docs to gitea-pages (push) Successful in 5m27s
Traceability Validation / Check Requirement Traces (push) Successful in 10s
Build & Release / Run Tests (push) Successful in 14m48s
🏗️ Build and Test JellyTau / Android Compile Check (push) Successful in 4m19s
Build & Release / Build Linux (push) Successful in 20m20s
Build & Release / Build Windows (push) Successful in 15m36s
Build & Release / Build Android (push) Successful in 30m46s
Build & Release / Create Release (push) Successful in 38s
🏗️ Build and Test JellyTau / Run Tests (push) Successful in 18m44s
🏗️ Build and Test JellyTau / Supply Chain (push) Failing after 49s
Publish Documentation / Build & publish docs to gitea-pages (push) Successful in 5m27s
Traceability Validation / Check Requirement Traces (push) Successful in 10s
Build & Release / Run Tests (push) Successful in 14m48s
🏗️ Build and Test JellyTau / Android Compile Check (push) Successful in 4m19s
Build & Release / Build Linux (push) Successful in 20m20s
Build & Release / Build Windows (push) Successful in 15m36s
Build & Release / Build Android (push) Successful in 30m46s
Build & Release / Create Release (push) Successful in 38s
Locking the screen kept a video's audio playing whether or not the background-audio button was on. Reported as "audio only mode is always active even if not selected". The button (UR-040) was built for the WebView <video> path, where losing visibility kills the decode: it chose between handing off to a native audio stream and letting playback stop. Native video then became the default renderer (DR-188), and on that path playback runs through ExoPlayer inside a MediaSessionService -- a foreground media service whose entire purpose is to keep playing while the app is hidden. Nothing stopped it, and nothing in the codebase paused on background. So the button governed a handoff that no longer had a gap to bridge. There was no interruption to paper over, and a user who never touched it got background playback anyway. The gating made it self-concealing: MainActivity.onStop only dispatched 'jellytau-background' when backgroundAudioEnabled was already true. The one notification that the app had gone away was itself conditional on the setting, so with the button OFF nothing could react even in principle. onStop and onStart now fire unconditionally and carry the two facts only the activity knows -- whether the toggle is armed, and whether Android put the window into picture-in-picture. What to do about it is decided in Rust (player/background_policy.rs), because it depends on whether the item has a picture to lose: video + toggle off -> Pause video + toggle on -> HandOffToAudio music, either -> KeepPlaying (no picture to give up) picture-in-picture -> KeepPlaying (the window is still on screen) It takes no renderer parameter on purpose. Two renderers with two behaviours and one toggle reaching only one of them is what produced the defect; a rule that cannot see the renderer cannot reproduce it. Two failure modes are deliberate. A decision call that fails leaves playback alone rather than risking silence mid-listen. An event with no detail -- older Kotlin against newer JS -- reads as "armed, not PiP", degrading to the previous behaviour instead of pausing unexpectedly. Foregrounding resumes only what backgrounding paused: a video the user paused themselves before locking stays paused. Written test-first per CLAUDE.md. The stub encoded today's behaviour (nothing ever pauses) and failed exactly as reported -- `left: KeepPlaying, right: Pause` -- before the rule was implemented. Verified on a device, R8-minified, both directions: [player_background_action] video=true armed=false pip=false -> Pause [player_background_action] video=true armed=true pip=false -> HandOffToAudio UR-040 / DR-224 / UT-211.
This commit is contained in:
@@ -840,6 +840,46 @@ pub async fn player_enter_background_audio(
|
||||
/// 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-224 | UT-211
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
pub async fn player_background_action(
|
||||
player: State<'_, PlayerStateWrapper>,
|
||||
background_audio_armed: bool,
|
||||
in_picture_in_picture: bool,
|
||||
) -> Result<crate::player::background_policy::BackgroundAction, String> {
|
||||
use crate::player::background_policy::{background_action, is_video_media, BackgroundAction};
|
||||
|
||||
let is_video = {
|
||||
let controller = player.0.lock().await;
|
||||
let queue_arc = controller.queue();
|
||||
let queue = queue_arc.lock().map_err(|e| e.to_string())?;
|
||||
match queue.current() {
|
||||
Some(item) => is_video_media(item.media_type),
|
||||
None => return Ok(BackgroundAction::KeepPlaying),
|
||||
}
|
||||
};
|
||||
|
||||
let action = background_action(is_video, background_audio_armed, in_picture_in_picture);
|
||||
info!(
|
||||
"[player_background_action] video={} armed={} pip={} -> {:?}",
|
||||
is_video, background_audio_armed, in_picture_in_picture, action
|
||||
);
|
||||
Ok(action)
|
||||
}
|
||||
|
||||
/// TRACES: UR-040 | DR-052 | UT-061, IT-013
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
|
||||
Reference in New Issue
Block a user