diff --git a/packages/hms_room_kit/lib/src/hls_viewer/hls_player_store.dart b/packages/hms_room_kit/lib/src/hls_viewer/hls_player_store.dart index a832fd55f..2ec08683b 100644 --- a/packages/hms_room_kit/lib/src/hls_viewer/hls_player_store.dart +++ b/packages/hms_room_kit/lib/src/hls_viewer/hls_player_store.dart @@ -223,17 +223,30 @@ class HLSPlayerStore extends ChangeNotifier ///[getHLSLayers] gets the HLS Layers void getHLSLayers() async { var layers = await HMSHLSPlayerController.getHLSLayers(); - layers.sort((a, b) => (b.bitrate ?? 0).compareTo(a.bitrate ?? 0)); int layersSize = layers.length; - if (layers[layersSize - 1].bitrate == 0 || - layers[layersSize - 1].bitrate == null) { - layerMap["AUTO"] = layers[layersSize - 1]; - } - layerMap["HIGH"] = layers[0]; - if (layersSize > 1) { - layerMap["LOW"] = layers[layersSize - 2]; + if (layersSize > 0) { + + ///This sorts the layers in descending order of bitrate + layers.sort((a, b) => (b.bitrate ?? 0).compareTo(a.bitrate ?? 0)); + + ///This checks for layer with zero or null bitrate and sets it to + ///"AUTO" key + if (layers[layersSize - 1].bitrate == 0 || + layers[layersSize - 1].bitrate == null) { + layerMap["AUTO"] = layers[layersSize - 1]; + } + + ///This picks up the highest bitrate layer from the sorted layers + layerMap["HIGH"] = layers[0]; + + ///This picks up the mid layer from the sorted layers + layerMap["MEDIUM"] = layers[layersSize ~/ 2]; + + ///This picks up the lowest bitrate layer from the sorted layers + if (layersSize > 1) { + layerMap["LOW"] = layers[layersSize - 2]; + } } - layerMap["MEDIUM"] = layers[layersSize ~/ 2]; } ///[getCurrentHLSLayer] gets the current HLS Layer @@ -252,17 +265,7 @@ class HLSPlayerStore extends ChangeNotifier } ///[setHLSLayer] sets the HLS Layer - void setHLSLayer(HMSHLSLayer? hmsHLSLayer) async { - if (hmsHLSLayer == null) { - if (Platform.isAndroid) { - HMSHLSPlayerController.setHLSLayer( - hmsHLSLayer: HMSHLSLayer(resolution: null, bitrate: null)); - } else { - HMSHLSPlayerController.setHLSLayer( - hmsHLSLayer: HMSHLSLayer(resolution: null, bitrate: 0)); - } - return; - } + void setHLSLayer(HMSHLSLayer hmsHLSLayer) async { selectedLayer = hmsHLSLayer; await HMSHLSPlayerController.setHLSLayer(hmsHLSLayer: hmsHLSLayer); notifyListeners(); diff --git a/packages/hmssdk_flutter/ios/Classes/HLSPlayer/HMSHLSPlayerAction.swift b/packages/hmssdk_flutter/ios/Classes/HLSPlayer/HMSHLSPlayerAction.swift index 8cff0a809..9c78e56fc 100644 --- a/packages/hmssdk_flutter/ios/Classes/HLSPlayer/HMSHLSPlayerAction.swift +++ b/packages/hmssdk_flutter/ios/Classes/HLSPlayer/HMSHLSPlayerAction.swift @@ -536,8 +536,7 @@ class HMSHLSPlayerAction { Here if the bitrate is nil we set it as zero otherwise the given bitrate is applied */ - if let bitrate = layer["bitrate"]{ - currentBitrate = bitrate + currentBitrate = layer["bitrate"] NotificationCenter.default.post( name: NSNotification.Name( HLS_PLAYER_METHOD @@ -546,24 +545,9 @@ class HMSHLSPlayerAction { userInfo: [ METHOD_CALL: "set_hls_layer", "result": result, - "bitrate": bitrate + "bitrate": layer["bitrate"] ?? 0 ] ) - }else{ - currentBitrate = nil - NotificationCenter.default.post( - name: NSNotification.Name( - HLS_PLAYER_METHOD - ), - object: nil, - userInfo: [ - METHOD_CALL: "", - "result": result, - "bitrate": 0 - ] - ) - } - }