Skip to content

Commit

Permalink
fix resolution changing logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Stepanokdev committed Nov 3, 2023
1 parent 8367e12 commit d3aaaf2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,18 @@ public class EncodedVideoPlayerViewModel: VideoPlayerViewModel {
}).store(in: &subscription)
}

func getBitRate() -> Double {
func getBitRate() -> CGSize {
switch appStorage.userSettings?.streamingQuality {
case .auto:
return 0
return CGSize(width: 1280, height: 720)
case .low:
return 1500000
return CGSize(width: 640, height: 360)
case .medium:
return 2000000
return CGSize(width: 854, height: 480)
case .high:
return 4000000
return CGSize(width: 1280, height: 720)
case .none:
return 0
return CGSize(width: 1280, height: 720)
}
}
}
8 changes: 4 additions & 4 deletions Course/Course/Presentation/Video/PlayerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ import _AVKit_SwiftUI
struct PlayerViewController: UIViewControllerRepresentable {

var videoURL: URL?
var bitrate: Double
var videoResolution: CGSize
var controller: AVPlayerViewController
var progress: ((Float) -> Void)
var seconds: ((Double) -> Void)

init(
videoURL: URL?,
controller: AVPlayerViewController,
bitrate: Double,
bitrate: CGSize,
progress: @escaping ((Float) -> Void),
seconds: @escaping ((Double) -> Void)
) {
self.videoURL = videoURL
self.controller = controller
self.bitrate = bitrate
self.videoResolution = bitrate
self.progress = progress
self.seconds = seconds
}
Expand Down Expand Up @@ -79,7 +79,7 @@ struct PlayerViewController: UIViewControllerRepresentable {
playerController.player = AVPlayer()
}
playerController.player?.replaceCurrentItem(with: AVPlayerItem(url: videoURL!))
playerController.player?.currentItem?.preferredPeakBitRate = bitrate
playerController.player?.currentItem?.preferredMaximumResolution = videoResolution
addPeriodicTimeObserver(playerController, currentProgress: { progress, seconds in
self.progress(progress)
self.seconds(seconds)
Expand Down

0 comments on commit d3aaaf2

Please sign in to comment.