Handle case where AVQueuePlayer doesnt update the current item for shorter audio segments

This commit is contained in:
Jackson Harper
2022-11-11 12:40:39 +08:00
parent 98df7164e5
commit be941faf39

View File

@ -672,6 +672,14 @@
case .reset:
if let playerItem = player.currentItem as? SpeechPlayerItem {
let itemElapsed = playerItem.status == .readyToPlay ? CMTimeGetSeconds(playerItem.currentTime()) : 0
if itemElapsed >= CMTimeGetSeconds(playerItem.duration) + 0.5 {
// Occasionally AV wont send an event for a new item starting for ~3s, if this
// happens we can try to manually update the time
if playerItem.speechItem.audioIdx + 1 < (document?.utterances.count ?? 0) {
currentAudioIndex = playerItem.speechItem.audioIdx + 1
}
}
timeElapsed = durationBefore(playerIndex: playerItem.speechItem.audioIdx) + itemElapsed
timeElapsedString = formatTimeInterval(timeElapsed)