When utilizing the AVAudioPlayer for playback, I am experiencing a 1 to 3 second delay when playing the audio over bluetooth. This delay is not present when disconnected from bluetooth and not present when speakers are connected directly to the device using an audio jack.
I have tried placing the AVAudioPlayer on it's own queue, I have also tried playing 1 second of pure silence before playing the actual audio:
extension AVAudioPlayer {
func prepareIntroToPlay() {
prepareToPlay()
volume = 0
play()
stop()
prepareToPlay()
}
}
I have also made my AVAudioPlayer a managing singleton, that plays the one second of silence on it's own queue. All this preperation still does not remove the AVAudioPlayer delay over Bluetooth.
I shouldn't really use the word "delay". If you had an AudioFile with a recording of "1, 2, 3, 4, 5, 6, 7, 8, 9, 10"; when connected to Bluetooth you would hear "4, 5, 6, 7, 8, 9, 10".
I have found this open radar: http://www.openradar.me/41482862 pertaining to the issue, but I am wondering if there is any work-around for this issue?
I am in need of my AVAudioPlayer to mix with other sounds, because I do have an MPMusicPlayerController that plays music as well (this seems unaffected by bluetooth audio, works fine).
Audio Player Session Config:
let session = AVAudioSession.sharedInstance()
try session.setCategory(.playback, options: .mixWithOthers)
try session.setActive(true, options: [])