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)
|
NSApp.setActivationPolicy(.regular)
|
||||||
#elseif os(iOS)
|
#elseif os(iOS)
|
||||||
// iOS: 配置音频会话(支持后台播放 + PiP)
|
// iOS: 配置音频会话(支持后台播放 + PiP)
|
||||||
configureAudioSession()
|
ensureAudioSession()
|
||||||
// 开启诊断日志文件
|
// 开启诊断日志文件
|
||||||
startDiagnosticLog()
|
startDiagnosticLog()
|
||||||
#endif
|
#endif
|
||||||
@ -187,16 +187,13 @@ final class PlayerBridge: ObservableObject {
|
|||||||
|
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
/// 配置 AVAudioSession,支持后台音频和 PiP
|
/// 配置 AVAudioSession,支持后台音频和 PiP
|
||||||
private func configureAudioSession() {
|
private func ensureAudioSession() {
|
||||||
do {
|
|
||||||
let session = AVAudioSession.sharedInstance()
|
let session = AVAudioSession.sharedInstance()
|
||||||
|
do {
|
||||||
try session.setCategory(.playback, mode: .default)
|
try session.setCategory(.playback, mode: .default)
|
||||||
try session.setActive(true)
|
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 {
|
} catch {
|
||||||
NSLog("[MiniPlayer] AVAudioSession setup failed: %@", error.localizedDescription)
|
diagLog("AudioSession error: \(error.localizedDescription)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -293,6 +290,9 @@ final class PlayerBridge: ObservableObject {
|
|||||||
let playerItem = AVPlayerItem(asset: asset)
|
let playerItem = AVPlayerItem(asset: asset)
|
||||||
|
|
||||||
player.replaceCurrentItem(with: playerItem)
|
player.replaceCurrentItem(with: playerItem)
|
||||||
|
#if os(iOS)
|
||||||
|
ensureAudioSession()
|
||||||
|
#endif
|
||||||
player.play()
|
player.play()
|
||||||
isPlaying = true
|
isPlaying = true
|
||||||
diagLog("play() called, rate=\(player.rate) timeControlStatus=\(player.timeControlStatus.rawValue)")
|
diagLog("play() called, rate=\(player.rate) timeControlStatus=\(player.timeControlStatus.rawValue)")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user