diff --git a/Sources/Utilities/MediaPlayer/MediaPlayer.swift b/Sources/Utilities/MediaPlayer/MediaPlayer.swift index 7d1f75d4..11bd4f5c 100644 --- a/Sources/Utilities/MediaPlayer/MediaPlayer.swift +++ b/Sources/Utilities/MediaPlayer/MediaPlayer.swift @@ -123,7 +123,7 @@ public class MediaPlayer: AVPlayer { } playWhenReady = false - setupPeriodicTimeObserver() + setupPlayerItemObserver() super.play() state = .playing } @@ -230,7 +230,10 @@ public class MediaPlayer: AVPlayer { // MARK: - Private Methods private extension MediaPlayer { func setupPlayerItemObserver() { - guard playerItemObserver == nil else { return } + guard playerItemObserver == nil else { + setupPeriodicTimeObserver() + return + } removePeriodicTimeObserver() playerItemObserver = currentItem?.observe(\.status, options: [.new, .old]) { [weak self] playerItem, _ in guard let self else { return } @@ -283,6 +286,7 @@ private extension MediaPlayer { func timeObserverCallback(time: CMTime) { guard time.seconds >= playbackInterval.endAt else { return } + // at this point, item has ended if allowsLooping { setPlaybackPosition(to: playbackInterval.startAt) play()