Skip to content

Commit

Permalink
+1
Browse files Browse the repository at this point in the history
  • Loading branch information
borut-t committed Oct 6, 2023
1 parent 1c27249 commit 8a18b3e
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Sources/Utilities/MediaPlayer/MediaPlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public class MediaPlayer: AVPlayer {
}

playWhenReady = false
setupPeriodicTimeObserver()
setupPlayerItemObserver()
super.play()
state = .playing
}
Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 8a18b3e

Please sign in to comment.