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()
|
||||
try session.setCategory(.playback, mode: .default)
|
||||
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 {
|
||||
NSLog("[MiniPlayer] AVAudioSession setup failed: \(error.localizedDescription)")
|
||||
NSLog("[MiniPlayer] AVAudioSession setup failed: %@", error.localizedDescription)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -242,6 +245,15 @@ final class PlayerBridge: ObservableObject {
|
||||
let item = queue[index]
|
||||
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,避免野指针
|
||||
itemStatusObserver?.invalidate()
|
||||
itemStatusObserver = nil
|
||||
@ -260,7 +272,7 @@ final class PlayerBridge: ObservableObject {
|
||||
player.replaceCurrentItem(with: playerItem)
|
||||
player.play()
|
||||
isPlaying = true
|
||||
print("[MiniPlayer] player.play() called, rate=\(player.rate)")
|
||||
print("[MiniPlayer] player.play() called, rate=\(player.rate), timeControlStatus=\(player.timeControlStatus.rawValue)")
|
||||
|
||||
cachedDuration = 0
|
||||
progressRatio = 0
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user