Fix for offline mode
🏗️ Build and Test JellyTau / Run Tests (pull_request) Successful in 4m21s
Traceability Validation / Check Requirement Traces (pull_request) Successful in 20s
🏗️ Build and Test JellyTau / Android Compile Check (pull_request) Successful in 4m54s

This commit is contained in:
2026-07-03 19:37:34 +02:00
parent c58cc0cf46
commit 2d141e5bf4
13 changed files with 790 additions and 143 deletions
+31 -10
View File
@@ -1422,13 +1422,14 @@ pub async fn player_play_album_track(
info!(" [{}] {} (ID: {})", idx, track.name, track.id);
}
// Find the index of the requested track
// Validate the requested track exists in the album (its position in the
// final queue is computed after building, since offline tracks are skipped).
info!("Looking for track_id: {}", request.track_id);
let start_index = tracks.iter()
let album_index = tracks.iter()
.position(|t| t.id == request.track_id)
.ok_or_else(|| format!("Track {} not found in album", request.track_id))?;
info!("Track {} is at index {} in album", request.track_id, start_index);
info!("Track {} is at index {} in album", request.track_id, album_index);
// Convert tracks to MediaItems
let mut media_items = Vec::new();
@@ -1443,13 +1444,21 @@ pub async fn player_play_album_track(
jellyfin_item_id: Some(jellyfin_id.clone()),
}
} else {
// Get stream URL from repository (works online/offline)
let stream_url = repository.get_audio_stream_url(&track.id).await
.map_err(|e| format!("Failed to get stream URL for {}: {}", track.name, e))?;
MediaSource::Remote {
stream_url,
jellyfin_item_id: jellyfin_id.clone(),
// Non-downloaded track: needs a stream URL from the server. When the
// server is unreachable (offline), skip this track rather than failing
// the whole album — downloaded tracks must still be playable.
match repository.get_audio_stream_url(&track.id).await {
Ok(stream_url) => MediaSource::Remote {
stream_url,
jellyfin_item_id: jellyfin_id.clone(),
},
Err(e) => {
warn!(
"[Player] Skipping track {} ({}) — no local download and stream URL unavailable: {}",
track.name, track.id, e
);
continue;
}
}
};
@@ -1489,6 +1498,18 @@ pub async fn player_play_album_track(
media_items.push(media_item);
}
if media_items.is_empty() {
return Err("No playable tracks available (offline and nothing downloaded)".to_string());
}
// Tracks with no local download and no reachable server were skipped above,
// so positions shifted. Re-locate the requested track in the built queue.
// If the tapped track itself was skipped, fall back to the first item.
let start_index = media_items
.iter()
.position(|item| item.id == request.track_id)
.unwrap_or(0);
info!("Built queue with {} media items, starting at index {}", media_items.len(), start_index);
// Handle shuffle before setting queue