我一直试图在Bluetooth扬声器上重现视频的音频,但由于音量太低,音频会失真。使用AVPlayer再现视频,并且在iOS 13上的设备上播放时声音正确 在研究过程中看到一些评论之后,我添加了代码:
do {
try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default, options: [.mixWithOthers, .allowBluetooth, .allowBluetoothA2DP,.defaultToSpeaker])
try AVAudioSession.sharedInstance().setActive(true)
} catch(let error) {
print("*** \(error) ***")
Crashlytics.crashlytics().record(error: error)
}
在AVPlayer初始化之前,初始化之后或在AppDelegate中,我在不同的位置尝试了先前的代码,
一些相关问题:
How to connect the audio to bluetooth when playing using AVPlayer
iOS Swift - Poor audio quality when using Bluetooth external speaker
AVAudioSession setCategory Swift 4.2 iOS 12 - Play Sound on Silent