From 0215565dd335ab69a0ce738c4ad8bf68dd2bc197 Mon Sep 17 00:00:00 2001 From: Stefano Russello Date: Thu, 18 May 2023 08:46:50 +0200 Subject: [PATCH] SMD-2149 Release iOS SDK - Improved bitrate selector --- Changelog.md | 3 +++ .../Controls/AMGPlayKitStandardControl.swift | 3 ++- .../Player/Media/MediaContext.swift | 18 +++++++++++++++++- StreamAMGSDK.podspec | 2 +- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/Changelog.md b/Changelog.md index c3d6323..d8521e1 100644 --- a/Changelog.md +++ b/Changelog.md @@ -3,6 +3,9 @@ Change Log: All notable changes to this project will be documented in this section. +### 1.2.2 +- Improved bitrate selector + ### 1.2.1 - Default subtitle track auto-selected - Get Label caption on subtitle selector diff --git a/Source/StreamSDKPlayKit/Player/Controls/AMGPlayKitStandardControl.swift b/Source/StreamSDKPlayKit/Player/Controls/AMGPlayKitStandardControl.swift index 142c8f3..1f091ec 100644 --- a/Source/StreamSDKPlayKit/Player/Controls/AMGPlayKitStandardControl.swift +++ b/Source/StreamSDKPlayKit/Player/Controls/AMGPlayKitStandardControl.swift @@ -737,7 +737,7 @@ class AMGPlayKitStandardControl: UIView, AMGControlDelegate { button.addTarget(self, action: #selector(swapBitRate(button:)), for: .touchUpInside) self.bitrateScroll.addSubview(button) withBitrateList.forEach { bitrate in - let button = createButtonLabel(text: "\(bitrate.bitrate ?? 0)", width: maxWidth, index: count, selectedIndex: self.selectedBitrate, colors: selectorColors) + let button = createButtonLabel(text: "\(bitrate.height ?? 0)p", width: maxWidth, index: count, selectedIndex: self.selectedBitrate, colors: selectorColors) button.addTarget(self, action: #selector(swapBitRate(button:)), for: .touchUpInside) self.bitrateScroll.addSubview(button) count += 1 @@ -770,6 +770,7 @@ class AMGPlayKitStandardControl: UIView, AMGControlDelegate { tText.setTitle(text, for: .normal) tText.setTitleColor(.white, for: .normal) tText.contentHorizontalAlignment = .left + tText.titleLabel?.lineBreakMode = .byWordWrapping tText.titleEdgeInsets = UIEdgeInsets(top: 0, left: 16, bottom: 0, right: 0) if index == selectedIndex { diff --git a/Source/StreamSDKPlayKit/Player/Media/MediaContext.swift b/Source/StreamSDKPlayKit/Player/Media/MediaContext.swift index a8f0d1b..61e86fc 100644 --- a/Source/StreamSDKPlayKit/Player/Media/MediaContext.swift +++ b/Source/StreamSDKPlayKit/Player/Media/MediaContext.swift @@ -11,7 +11,23 @@ public struct MediaContext: Codable { public let flavorAssets: [FlavorAsset] public func fetchBitrates() -> [FlavorAsset] { - return flavorAssets.sorted(by: {$0.width ?? 0 < $1.width ?? 0}) + var uniqueAssets: [Int: FlavorAsset] = [:] // Dictionary to store unique assets by height + + for flavorAsset in flavorAssets { + if let height = flavorAsset.height { + if let existingAsset = uniqueAssets[Int(height)] { + if let existingBitrate = existingAsset.bitrate, let currentBitrate = flavorAsset.bitrate { + if existingBitrate < currentBitrate { + uniqueAssets[Int(height)] = flavorAsset // Replace with higher bitrate asset + } + } + } else { + uniqueAssets[Int(height)] = flavorAsset // Add new unique asset + } + } + } + + return Array(uniqueAssets.values).sorted { $0.bitrate ?? 0 < $1.bitrate ?? 0 } // Convert dictionary values to an array and return it sorted } } diff --git a/StreamAMGSDK.podspec b/StreamAMGSDK.podspec index 79b91e3..0bea79f 100644 --- a/StreamAMGSDK.podspec +++ b/StreamAMGSDK.podspec @@ -2,7 +2,7 @@ Pod::Spec.new do |spec| spec.name = "StreamAMGSDK" - spec.version = "1.2.1" + spec.version = "1.2.2" spec.summary = "Stream AMG SDK" spec.swift_versions = "5"