iOS: Random Album Radio plays whole albums in random order, loading each next album lazily
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a4c870251c
commit
3e832e3125
3 files changed
+45
-13
No files matched your search
@@ -79,14 +79,12 @@ struct LibraryHome: View {
|
||||
}
|
||||
if ready {
|
||||
SectionTitle(title: "Stations")
|
||||
let stations: [(String, String, () async throws -> [Track])] = [
|
||||
("dot.radiowaves.left.and.right", "Library Radio", { try await g.plex.allTracksShuffled() }),
|
||||
("square.stack", "Random Album Radio", {
|
||||
// Whole albums in random order, across the entire library.
|
||||
var out: [Track] = []
|
||||
for a in try await g.plex.albums().shuffled() { out += try await g.plex.albumTracks(a.ratingKey) }
|
||||
return out
|
||||
let stations: [(String, String, () async throws -> Void)] = [
|
||||
("dot.radiowaves.left.and.right", "Library Radio", {
|
||||
let list = try await g.plex.allTracksShuffled()
|
||||
if !list.isEmpty { g.playback.playTracks(list) }
|
||||
}),
|
||||
("square.stack", "Random Album Radio", { try await g.playback.startAlbumRadio() }),
|
||||
]
|
||||
let shown = ordered(stations) { $0.1 }
|
||||
ForEach(shown, id: \.1) { st in
|
||||
@@ -126,12 +124,10 @@ struct LibraryHome: View {
|
||||
}
|
||||
|
||||
/// Starts a station: its songs play in the order given (albums stay whole).
|
||||
private func play(_ load: @escaping () async throws -> [Track]) {
|
||||
private func play(_ start: @escaping () async throws -> Void) {
|
||||
Task {
|
||||
do {
|
||||
let list = try await load()
|
||||
if list.isEmpty { ui.overlays.hud("Nothing to play", "music.note") } else { g.playback.playTracks(list) }
|
||||
} catch { ui.overlays.hud("Couldn't start station", "exclamationmark.triangle") }
|
||||
do { try await start() }
|
||||
catch { ui.overlays.hud("Couldn't start station", "exclamationmark.triangle") }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user