Compare commits

..
Author SHA1 Message Date
rootandClaude Opus 5.5 8c8157c489 Folded Now Playing: use the bottom space, bigger art (dev 39)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 17:14:49 -08:00
rootandClaude Opus 5.5 1d7576371a Play from Plex when the stem server is off or unreachable (dev 38)
Stems are used only when the stem server is online or they're fully
downloaded. A failed stem open falls back to Plex's own file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 17:10:19 -08:00
3 changed files with 42 additions and 13 deletions

No files matched your search

+37 -9
View File
@@ -639,7 +639,7 @@ final class PlaybackManager: StemEngineListener, @unchecked Sendable {
/// True when [track] would play without the home network: its stems (or, lacking stems, its file) are fully cached.
func playableOffline(_ track: Track) -> Bool {
if let entry = stems.find(track) {
return StemQuality.allCases.contains { q in entry.stems.allSatisfy { cache.isComplete(Self.stemKey(entry, $0.file, $0.size, q)) } }
return stemsCached(entry)
}
return track.partKey != nil && cache.isComplete(Self.plexKey(track))
}
@@ -721,29 +721,57 @@ final class PlaybackManager: StemEngineListener, @unchecked Sendable {
}
private func openDetached(_ track: Track, _ startMs: Int64) async throws -> (TrackSession, StemEntry?) {
// Plain Plex files need a playback session first, or a Remote Access upload limit fails them.
let plain = stems.find(track) == nil && !cache.isComplete(Self.plexKey(track))
// Stems when the stem server can serve them (or they're downloaded); Plex's own file otherwise.
// Stemify works as a plain Plex player: a stem server that's off or out of reach only costs the stems.
if let entry = await stemsToPlay(track) {
do {
return try await openOn(track, startMs, entry, nil)
} catch {
if Task.isCancelled { throw error }
Log.shared.error("play", "stems for \(track.title) failed (\(error.localizedDescription)), playing from Plex")
Task.detached { [stems] in await stems.refresh() }
}
}
let plain = !cache.isComplete(Self.plexKey(track))
let stream = plain ? await plex.streamUrl(track) : nil
do {
return try await openOn(track, startMs, stream)
return try await openOn(track, startMs, nil, stream)
} catch {
// A dead saved address (left home, network changed): pick a working one and try once more.
guard plain, !Task.isCancelled, await plex.reroute("stream failed") else { throw error }
return try await openOn(track, startMs, await plex.streamUrl(track))
return try await openOn(track, startMs, nil, await plex.streamUrl(track))
}
}
private func openOn(_ track: Track, _ startMs: Int64, _ stream: URL?) async throws -> (TrackSession, StemEntry?) {
/// The stem entry to play, or nil to play Plex's file: skips stems the stem server can't
/// serve right now unless they're fully downloaded.
private func stemsToPlay(_ track: Track) async -> StemEntry? {
guard let entry = stems.find(track) else { return nil }
if stemsCached(entry) { return entry }
// Right after launch the first check may still be running: give it a few seconds
// rather than sit through a long timeout on a server that isn't there.
var waited = 0
while case .unknown = stems.status, waited < 30, !Task.isCancelled {
try? await Task.sleep(nanoseconds: 100_000_000); waited += 1
}
if case .online = stems.status { return entry }
return nil
}
private func stemsCached(_ entry: StemEntry) -> Bool {
StemQuality.allCases.contains { q in entry.stems.allSatisfy { cache.isComplete(Self.stemKey(entry, $0.file, $0.size, q)) } }
}
private func openOn(_ track: Track, _ startMs: Int64, _ entry: StemEntry?, _ stream: URL?) async throws -> (TrackSession, StemEntry?) {
try await withCheckedThrowingContinuation { cont in
DispatchQueue.global(qos: .userInitiated).async { [self] in
cont.resume(with: Result { try open(track, startMs, stream: stream) })
cont.resume(with: Result { try open(track, startMs, entry: entry, stream: stream) })
}
}
}
/// Opens every stem (or the original file) and waits for the decoders to know their format.
private func open(_ track: Track, _ startMs: Int64, stream: URL? = nil) throws -> (TrackSession, StemEntry?) {
let entry = stems.find(track)
private func open(_ track: Track, _ startMs: Int64, entry: StemEntry?, stream: URL? = nil) throws -> (TrackSession, StemEntry?) {
var sources: [(name: String, key: String, url: URL?, hint: String)] = []
if let entry {
let q = qualityFor(entry)
@@ -118,7 +118,7 @@ struct NowPlayingScreen: View {
@Environment(\.verticalSizeClass) private var vSize
/// Folded iPhone Duo: the outer display keeps a status column down the right edge.
@State private var folded = false
private var artInset: CGFloat { tight ? 18 : 28 }
private var artInset: CGFloat { tight ? 18 : folded ? 12 : 28 }
private var hPad: CGFloat { tight ? 20 : 28 }
private var g: AppGraph { .shared }
@@ -167,11 +167,12 @@ struct NowPlayingScreen: View {
// Folded, the iPhone Duo keeps a status column down the right edge. Run the player under it
// (it only overlaps the sliding preset chips) instead of leaving a quarter of the screen empty.
// Upright iPhones have no side insets, so this only changes the Duo.
.ignoresSafeArea(.container, edges: !docked && vSize == .regular ? .trailing : [])
// Folded, the bottom inset is empty space too: run the controls down into it, and the art grows into the room.
.ignoresSafeArea(.container, edges: !docked && vSize == .regular ? (folded ? [.trailing, .bottom] : .trailing) : [])
// Measured outside the line above, so it still sees the status column.
.onGeometryChange(for: Bool.self) { $0.safeAreaInsets.trailing > 20 } action: { folded = $0 && vSize == .regular }
.padding(.top, docked ? 4 : tight ? 14 : 20)
.padding(.bottom, tight ? 4 : 8)
.padding(.bottom, tight ? 4 : folded ? 2 : 8)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(c.bg.ignoresSafeArea())
.overlay(alignment: .top) {
+1 -1
View File
@@ -9,7 +9,7 @@ settings:
# iOS needs a plain number for the bundle version; the label is what the app and releases show.
MARKETING_VERSION: "0.9.0"
VERSION_LABEL: "0.9.0"
CURRENT_PROJECT_VERSION: "37"
CURRENT_PROJECT_VERSION: "39"
# Dev builds override these (build-ipa.sh dev) so they install next to the release app.
APP_ID: org.cdnutter.stemify
APP_NAME: Stemify