mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Update UI after seeking, dont try to detect end of stream using currentTime
This helps with two issues: - after seeking sometimes you will see the loading spinner even after audio has resumed. - sometimes if we are still pulling data we might detect that we are at the end of the stream.
This commit is contained in:
parent
f6a3b7091c
commit
460ba07e30
1 changed files with 2 additions and 11 deletions
|
|
@ -212,7 +212,6 @@ public class AudioController: NSObject, ObservableObject, AVAudioPlayerDelegate
|
|||
// within this index, but this is probably accurate enough for now.
|
||||
player?.removeAllItems()
|
||||
synthesizeFrom(start: foundIdx, playWhenReady: state == .playing, atOffset: remainder)
|
||||
return
|
||||
} else {
|
||||
// There was no foundIdx, so we are probably trying to seek past the end, so
|
||||
// just seek to the last possible duration.
|
||||
|
|
@ -221,6 +220,7 @@ public class AudioController: NSObject, ObservableObject, AVAudioPlayerDelegate
|
|||
synthesizeFrom(start: durations.count - 1, playWhenReady: state == .playing, atOffset: last)
|
||||
}
|
||||
}
|
||||
fireTimer()
|
||||
}
|
||||
|
||||
@AppStorage(UserDefaultKey.textToSpeechPlaybackRate.rawValue) public var playbackRate = 1.0 {
|
||||
|
|
@ -299,8 +299,7 @@ public class AudioController: NSObject, ObservableObject, AVAudioPlayerDelegate
|
|||
if state == .reachedEnd {
|
||||
return false
|
||||
}
|
||||
return
|
||||
itemAudioProperties?.itemID == itemID &&
|
||||
return itemAudioProperties?.itemID == itemID &&
|
||||
(state == .loading || player?.currentItem == nil || player?.currentItem?.status == .unknown)
|
||||
}
|
||||
|
||||
|
|
@ -431,7 +430,6 @@ public class AudioController: NSObject, ObservableObject, AVAudioPlayerDelegate
|
|||
|
||||
func startTimer() {
|
||||
if timer == nil {
|
||||
// Update every 100ms
|
||||
timer = Timer.scheduledTimer(timeInterval: 0.1, target: self, selector: #selector(fireTimer), userInfo: nil, repeats: true)
|
||||
timer?.fire()
|
||||
}
|
||||
|
|
@ -445,13 +443,6 @@ public class AudioController: NSObject, ObservableObject, AVAudioPlayerDelegate
|
|||
stop()
|
||||
}
|
||||
|
||||
if player.items().count == 1, let currentTime = player.currentItem?.currentTime(), let duration = player.currentItem?.duration {
|
||||
if currentTime >= duration {
|
||||
pause()
|
||||
state = .reachedEnd
|
||||
}
|
||||
}
|
||||
|
||||
if let durations = durations {
|
||||
duration = durations.reduce(0, +)
|
||||
durationString = formatTimeInterval(duration)
|
||||
|
|
|
|||
Loading…
Reference in a new issue