Skip to content

Commit

Permalink
[Bugfix] Fix player rate is not sync with UI after playing next
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle-Ye committed Nov 8, 2023
1 parent 96e8684 commit 6e4d41b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class CommonPlayerViewController: AVPlayerViewController {
UIAction(title: playSpeed.name, state: player?.rate ?? 1 == playSpeed.value ? .on : .off) { [weak self] _ in
self?.player?.currentItem?.audioTimePitchAlgorithm = .timeDomain
if #available(tvOS 16.0, *) {
self?.selectSpeed(AVPlaybackSpeed(rate: playSpeed.value, localizedName: playSpeed.name))
self?.player?.defaultRate = playSpeed.value
} else {
self?.player?.rate = playSpeed.value
}
Expand Down
8 changes: 6 additions & 2 deletions BilibiliLive/Component/Video/VideoPlayerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,11 @@ extension VideoPlayerViewController {
}

playerItem = AVPlayerItem(asset: asset)
player = AVPlayer(playerItem: playerItem)
player?.addPeriodicTimeObserver(forInterval: CMTime(seconds: 1, preferredTimescale: 1), queue: .main) { [weak self] time in
let player = AVPlayer(playerItem: playerItem)
if #available(tvOS 16.0, *), let defaultRate = self.player?.defaultRate {
player.defaultRate = defaultRate
}
player.addPeriodicTimeObserver(forInterval: CMTime(seconds: 1, preferredTimescale: 1), queue: .main) { [weak self] time in
guard let self else { return }
if self.danMuView.isHidden { return }
let seconds = time.seconds
Expand Down Expand Up @@ -421,5 +424,6 @@ extension VideoPlayerViewController {
}
}
}
self.player = player
}
}

0 comments on commit 6e4d41b

Please sign in to comment.