fix: add diagnostics for local file playback — file existence, audio route, player rate
This commit is contained in:
parent
58c34250c5
commit
0388ae2a45
@ -168,9 +168,12 @@ final class PlayerBridge: ObservableObject {
|
|||||||
let session = AVAudioSession.sharedInstance()
|
let session = AVAudioSession.sharedInstance()
|
||||||
try session.setCategory(.playback, mode: .default)
|
try session.setCategory(.playback, mode: .default)
|
||||||
try session.setActive(true)
|
try session.setActive(true)
|
||||||
NSLog("[MiniPlayer] AVAudioSession configured: playback + default")
|
let route = session.currentRoute
|
||||||
|
let outputs = route.outputs.map { "\($0.portName)(\($0.portType.rawValue))" }.joined(separator: ", ")
|
||||||
|
NSLog("[MiniPlayer] AVAudioSession configured: playback+default, outputs=[%@], secondaryAudioShouldBeSilencedHint=%d",
|
||||||
|
outputs, session.secondaryAudioShouldBeSilencedHint)
|
||||||
} catch {
|
} catch {
|
||||||
NSLog("[MiniPlayer] AVAudioSession setup failed: \(error.localizedDescription)")
|
NSLog("[MiniPlayer] AVAudioSession setup failed: %@", error.localizedDescription)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -242,6 +245,15 @@ final class PlayerBridge: ObservableObject {
|
|||||||
let item = queue[index]
|
let item = queue[index]
|
||||||
print("[MiniPlayer] playIndex(\(index)): \(item.url.absoluteString)")
|
print("[MiniPlayer] playIndex(\(index)): \(item.url.absoluteString)")
|
||||||
|
|
||||||
|
// 本地文件诊断:检查文件是否存在和可读
|
||||||
|
if item.url.isFileURL {
|
||||||
|
let path = item.url.path
|
||||||
|
let exists = FileManager.default.fileExists(atPath: path)
|
||||||
|
let readable = FileManager.default.isReadableFile(atPath: path)
|
||||||
|
let fileSize = (try? FileManager.default.attributesOfItem(atPath: path)[.size] as? Int) ?? 0
|
||||||
|
print("[MiniPlayer] Local file check: exists=\(exists), readable=\(readable), size=\(fileSize), path=\(path)")
|
||||||
|
}
|
||||||
|
|
||||||
// 先清除旧的 KVO,避免野指针
|
// 先清除旧的 KVO,避免野指针
|
||||||
itemStatusObserver?.invalidate()
|
itemStatusObserver?.invalidate()
|
||||||
itemStatusObserver = nil
|
itemStatusObserver = nil
|
||||||
@ -260,7 +272,7 @@ final class PlayerBridge: ObservableObject {
|
|||||||
player.replaceCurrentItem(with: playerItem)
|
player.replaceCurrentItem(with: playerItem)
|
||||||
player.play()
|
player.play()
|
||||||
isPlaying = true
|
isPlaying = true
|
||||||
print("[MiniPlayer] player.play() called, rate=\(player.rate)")
|
print("[MiniPlayer] player.play() called, rate=\(player.rate), timeControlStatus=\(player.timeControlStatus.rawValue)")
|
||||||
|
|
||||||
cachedDuration = 0
|
cachedDuration = 0
|
||||||
progressRatio = 0
|
progressRatio = 0
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user