fix: ensure AVAudioSession is active right before player.play(), add diagnostic logging
This commit is contained in:
parent
15b26ce416
commit
beaeb3b4c6
@ -153,7 +153,7 @@ final class PlayerBridge: ObservableObject {
|
||||
NSApp.setActivationPolicy(.regular)
|
||||
#elseif os(iOS)
|
||||
// iOS: 配置音频会话(支持后台播放 + PiP)
|
||||
configureAudioSession()
|
||||
ensureAudioSession()
|
||||
// 开启诊断日志文件
|
||||
startDiagnosticLog()
|
||||
#endif
|
||||
@ -187,16 +187,13 @@ final class PlayerBridge: ObservableObject {
|
||||
|
||||
#if os(iOS)
|
||||
/// 配置 AVAudioSession,支持后台音频和 PiP
|
||||
private func configureAudioSession() {
|
||||
private func ensureAudioSession() {
|
||||
let session = AVAudioSession.sharedInstance()
|
||||
do {
|
||||
let session = AVAudioSession.sharedInstance()
|
||||
try session.setCategory(.playback, mode: .default)
|
||||
try session.setActive(true)
|
||||
let route = session.currentRoute
|
||||
let outputs = route.outputs.map { "\($0.portName)(\($0.portType.rawValue))" }.joined(separator: ", ")
|
||||
NSLog("[MiniPlayer] AVAudioSession configured: playback, outputs=[%@]", outputs)
|
||||
} catch {
|
||||
NSLog("[MiniPlayer] AVAudioSession setup failed: %@", error.localizedDescription)
|
||||
diagLog("AudioSession error: \(error.localizedDescription)")
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -293,6 +290,9 @@ final class PlayerBridge: ObservableObject {
|
||||
let playerItem = AVPlayerItem(asset: asset)
|
||||
|
||||
player.replaceCurrentItem(with: playerItem)
|
||||
#if os(iOS)
|
||||
ensureAudioSession()
|
||||
#endif
|
||||
player.play()
|
||||
isPlaying = true
|
||||
diagLog("play() called, rate=\(player.rate) timeControlStatus=\(player.timeControlStatus.rawValue)")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user