Skip to content

Commit

Permalink
Updated changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Decoder07 committed Apr 30, 2024
1 parent 0f2bc4a commit 756a4c8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 38 deletions.
43 changes: 23 additions & 20 deletions packages/hms_room_kit/lib/src/hls_viewer/hls_player_store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
]
)
}

}


Expand Down

0 comments on commit 756a4c8

Please sign in to comment.