I have to use AVAudioPlayer
as it supports playback rate but it doesn't support creating the instance of AVAudioPlayer in sleep device mode.
My solution is to create arrays of AVAudioPlayer before the device will be slept.
When the current audio is finished you should to get the next instance from stored array.
You can check it here
let players = [AVAudioPlayer]()
let index = 0
do {
player = [
try AVAudioPlayer(contentsOf: url1),
try AVAudioPlayer(contentsOf: url2),
try AVAudioPlayer(contentsOf: url3)
]
} catch {
print(error)
}
players[index].play()
func audioPlayerDidFinishPlaying(_ player: AVAudioPlayer, successfully flag: Bool) {
if flag {
index += 1
players[index].play()
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…