Skip to content

Commit

Permalink
feat(SUP-39506): iOS - mobile SDK - add control for bitrate and resol…
Browse files Browse the repository at this point in the history
…ution capping (#472)

* fix(SUP-39506): iOS - mobile SDK - add control for bitrate and resolution capping

* add tvOS minimum version
  • Loading branch information
inbalvasserman authored Nov 1, 2023
1 parent 242c34a commit 1bf723f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ extension AVPlayerEngine {
if #available(iOS 10.0, tvOS 10.0, *) {
playerItem.preferredForwardBufferDuration = newAsset.playerSettings.network.preferredForwardBufferDuration
}

if #available(iOS 11.0, tvOS 11.0, *) {
playerItem.preferredMaximumResolution = newAsset.playerSettings.network.preferredMaximumResolution
}

// Add observers
self.removeObservers()
Expand Down
14 changes: 14 additions & 0 deletions Classes/Player/PKPlayerSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ typealias SettingsChange = ((PlayerSettingsType) -> Void)
}
}

/// Indicates ta preferred maximum video resolution
///
/// Set preferredMaximumResolution to non-zero to indicates a preferred maximum video resolution. This property only applies to HTTP Live Streaming assets.
/// zero is the default value and it indicates there is no limit on the video resolution
///
/// @available(iOS 11.0, tvOS 11.0, *) via AVPlayerItem
@objc public var preferredMaximumResolution: CGSize = CGSize(width: 0, height: 0){
didSet {
self.onChange?(.preferredMaximumResolution(preferredMaximumResolution))
}
}

/// Indicates the media duration the caller prefers the player to buffer from the network ahead of the playhead to guard against playback disruption.
///
/// The value is in seconds. If it is set to 0, the player will choose an appropriate level of buffering for most use cases.
Expand Down Expand Up @@ -65,6 +77,7 @@ typealias SettingsChange = ((PlayerSettingsType) -> Void)
@objc public func createCopy() -> PKNetworkSettings {
let copy = PKNetworkSettings()
copy.preferredPeakBitRate = self.preferredPeakBitRate
copy.preferredMaximumResolution = self.preferredMaximumResolution
copy.preferredForwardBufferDuration = self.preferredForwardBufferDuration
copy.automaticallyWaitsToMinimizeStalling = self.automaticallyWaitsToMinimizeStalling

Expand Down Expand Up @@ -143,6 +156,7 @@ typealias SettingsChange = ((PlayerSettingsType) -> Void)

enum PlayerSettingsType {
case preferredPeakBitRate(Double)
case preferredMaximumResolution(CGSize)
case preferredForwardBufferDuration(Double)
case automaticallyWaitsToMinimizeStalling(Bool)
case configuredTimeOffsetFromLive(CMTime)
Expand Down
4 changes: 4 additions & 0 deletions Classes/Player/PlayerWrapper/AVPlayerWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ open class AVPlayerWrapper: NSObject, PlayerEngine {
switch settingsType {
case .preferredPeakBitRate(let preferredPeakBitRate):
self.currentPlayer.currentItem?.preferredPeakBitRate = preferredPeakBitRate
case .preferredMaximumResolution(let preferredMaximumResolution):
if #available(iOS 11.0, tvOS 11.0, *) {
self.currentPlayer.currentItem?.preferredMaximumResolution = preferredMaximumResolution
}
case .preferredForwardBufferDuration(let preferredForwardBufferDuration):
if #available(iOS 10.0, tvOS 10.0, *) {
self.currentPlayer.currentItem?.preferredForwardBufferDuration = preferredForwardBufferDuration
Expand Down

0 comments on commit 1bf723f

Please sign in to comment.