diff --git a/Classes/Player/AVPlayerEngine/AVPlayerEngine+AssetLoading.swift b/Classes/Player/AVPlayerEngine/AVPlayerEngine+AssetLoading.swift index e7ae0ea2..28ed1100 100644 --- a/Classes/Player/AVPlayerEngine/AVPlayerEngine+AssetLoading.swift +++ b/Classes/Player/AVPlayerEngine/AVPlayerEngine+AssetLoading.swift @@ -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() diff --git a/Classes/Player/PKPlayerSettings.swift b/Classes/Player/PKPlayerSettings.swift index 9b5b3dae..6ce069a6 100644 --- a/Classes/Player/PKPlayerSettings.swift +++ b/Classes/Player/PKPlayerSettings.swift @@ -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. @@ -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 @@ -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) diff --git a/Classes/Player/PlayerWrapper/AVPlayerWrapper.swift b/Classes/Player/PlayerWrapper/AVPlayerWrapper.swift index 18b95192..059a2fbf 100644 --- a/Classes/Player/PlayerWrapper/AVPlayerWrapper.swift +++ b/Classes/Player/PlayerWrapper/AVPlayerWrapper.swift @@ -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