Merge pull request #391 from ronaldheft/fix-ios-pause-during-seek

fix: Player sometimes pauses during seek on iOS
This commit is contained in:
advplyr 2022-09-23 15:37:50 -05:00 committed by GitHub
commit 4da31f5850
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -251,13 +251,13 @@ class AudioPlayer: NSObject {
self.seek(playbackSession.currentTime, from: "queueItemStatusObserver")
}
// Mark the player as ready
self.status = 0
// Start the player, if requested
if self.playWhenReady {
self.playWhenReady = false
self.play()
self.play(allowSeekBack: false, isInitializing: true)
} else {
// Mark the player as ready
self.status = 0
}
} else if (playerItem.status == .failed) {
logger.error("queueStatusObserver: FAILED \(playerItem.error?.localizedDescription ?? "")")
@ -281,8 +281,8 @@ class AudioPlayer: NSObject {
}
// MARK: - Methods
public func play(allowSeekBack: Bool = false) {
guard self.isInitialized() else { return }
public func play(allowSeekBack: Bool = false, isInitializing: Bool = false) {
guard self.isInitialized() || isInitializing else { return }
guard let session = self.getPlaybackSession() else {
NotificationCenter.default.post(name: NSNotification.Name(PlayerEvents.failed.rawValue), object: nil)
return
@ -353,7 +353,7 @@ class AudioPlayer: NSObject {
self.pause()
logger.log("SEEK: Seek to \(to) from \(from)")
logger.log("SEEK: Seek to \(to) from \(from) and continuePlaying(\(continuePlaying)")
guard let playbackSession = self.getPlaybackSession() else { return }
@ -392,6 +392,7 @@ class AudioPlayer: NSObject {
DispatchQueue.runOnMainQueue {
self.audioPlayer.seek(to: CMTime(seconds: seekTime, preferredTimescale: 1000)) { [weak self] completed in
self?.logger.log("SEEK: Completion handler called and continuePlaying(\(continuePlaying)")
guard completed else {
self?.logger.log("SEEK: WARNING: seeking not completed (to \(seekTime)")
return