Skip to content

Commit

Permalink
Added check tick on selected layer
Browse files Browse the repository at this point in the history
  • Loading branch information
Decoder07 committed Apr 30, 2024
1 parent 50c9a4c commit 0f2bc4a
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 71 deletions.
29 changes: 26 additions & 3 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 @@ -8,6 +8,7 @@ import 'dart:io';
///Package imports
import 'package:flutter/material.dart';
import 'package:hmssdk_flutter/hmssdk_flutter.dart';
import 'package:collection/collection.dart';

///Project imports
import 'package:hms_room_kit/src/layout_api/hms_room_layout.dart';
Expand Down Expand Up @@ -219,6 +220,7 @@ class HLSPlayerStore extends ChangeNotifier
notifyListeners();
}

///[getHLSLayers] gets the HLS Layers
void getHLSLayers() async {
var layers = await HMSHLSPlayerController.getHLSLayers();
layers.sort((a, b) => (b.bitrate ?? 0).compareTo(a.bitrate ?? 0));
Expand All @@ -234,12 +236,33 @@ class HLSPlayerStore extends ChangeNotifier
layerMap["MEDIUM"] = layers[layersSize ~/ 2];
}

///[getCurrentHLSLayer] gets the current HLS Layer
void getCurrentHLSLayer() async {
var layer = await HMSHLSPlayerController.getCurrentHLSLayer();
selectedLayer = layer;

///Here we are finding the layer with the same bitrate as the current layer
var layerSelected = layerMap.entries.firstWhereIndexedOrNull(
(index, element) => (element.value.bitrate == layer?.bitrate));

///If the layer is found we set the selected layer to that layer
if (layerSelected != null) {
selectedLayer = layerSelected.value;
}
notifyListeners();
}

void setHLSLayer(HMSHLSLayer hmsHLSLayer) async {
///[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;
}
selectedLayer = hmsHLSLayer;
await HMSHLSPlayerController.setHLSLayer(hmsHLSLayer: hmsHLSLayer);
notifyListeners();
Expand All @@ -253,7 +276,7 @@ class HLSPlayerStore extends ChangeNotifier

@override
void onHLSEventUpdate({required HMSHLSPlayerStats playerStats}) {
log("onHLSEventUpdate-> distanceFromLive: ${playerStats.distanceFromLive} buffered duration: ${playerStats.bufferedDuration}");
log("onHLSEventUpdate-> distanceFromLive: ${playerStats.distanceFromLive}ms buffered duration: ${playerStats.bufferedDuration}ms bitrate: ${playerStats.averageBitrate}");
isLive = playerStats.distanceFromLive < timeBeforeLive;
timeFromLive = Duration(milliseconds: playerStats.distanceFromLive.toInt());
hlsPlayerStats = playerStats;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ class _HLSViewerQualitySelectorBottomSheetState
Widget build(BuildContext context) {
double height = MediaQuery.of(context).size.height;
return SizedBox(
height: MediaQuery.of(context).orientation == Orientation.landscape? height * 0.8: height * 0.4,
width: ,
height: MediaQuery.of(context).orientation == Orientation.landscape
? height * 0.8
: height * 0.4,
child: Container(
decoration: BoxDecoration(
borderRadius: const BorderRadius.only(
Expand All @@ -59,8 +60,7 @@ class _HLSViewerQualitySelectorBottomSheetState
children: [
HMSTitleText(
text: "Quality",
textColor:
HMSThemeColors.onSurfaceHighEmphasis,
textColor: HMSThemeColors.onSurfaceHighEmphasis,
letterSpacing: 0.15,
),
],
Expand All @@ -81,42 +81,51 @@ class _HLSViewerQualitySelectorBottomSheetState
child: ListView.builder(
itemCount: data.item2,
itemBuilder: (context, index) {
return ListTile(
horizontalTitleGap: 2,
enabled: false,
contentPadding: EdgeInsets.zero,
title: HMSSubtitleText(
text:
data.item1.entries.elementAt(index).key,
fontSize: 14,
lineHeight: 20,
letterSpacing: 0.10,
fontWeight: FontWeight.w600,
textColor:
HMSThemeColors.onSurfaceHighEmphasis,
),
trailing: context
.read<HLSPlayerStore>()
.selectedLayer ==
data.item1.entries
.elementAt(index)
.value
? SizedBox(
height: 24,
width: 24,
child: SvgPicture.asset(
"packages/hms_room_kit/lib/src/assets/icons/tick.svg",
fit: BoxFit.scaleDown,
colorFilter: ColorFilter.mode(
HMSThemeColors
.onSurfaceHighEmphasis,
BlendMode.srcIn),
return GestureDetector(
onTap: () {
context.read<HLSPlayerStore>().setHLSLayer(
data.item1.entries
.elementAt(index)
.value);
Navigator.pop(context);
},
child: ListTile(
horizontalTitleGap: 2,
enabled: false,
contentPadding: EdgeInsets.zero,
title: HMSSubtitleText(
text:
data.item1.entries.elementAt(index).key,
fontSize: 14,
lineHeight: 20,
letterSpacing: 0.10,
fontWeight: FontWeight.w600,
textColor:
HMSThemeColors.onSurfaceHighEmphasis,
),
trailing: context
.read<HLSPlayerStore>()
.selectedLayer ==
data.item1.entries
.elementAt(index)
.value
? SizedBox(
height: 24,
width: 24,
child: SvgPicture.asset(
"packages/hms_room_kit/lib/src/assets/icons/tick.svg",
fit: BoxFit.scaleDown,
colorFilter: ColorFilter.mode(
HMSThemeColors
.onSurfaceHighEmphasis,
BlendMode.srcIn),
),
)
: const SizedBox(
height: 24,
width: 24,
),
)
: const SizedBox(
height: 24,
width: 24,
),
),
);
}),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ class ForegroundTaskHandler extends TaskHandler {
@override
void onStart(DateTime timestamp, SendPort? sendPort) async {
_sendPort = sendPort;

// You can use the getData function to get the stored data.
final customData =
await FlutterForegroundTask.getData<String>(key: 'customData');
print('customData: $customData');
}

// Called every [interval] milliseconds in [ForegroundTaskOptions].
Expand Down Expand Up @@ -51,6 +46,7 @@ class ForegroundTaskHandler extends TaskHandler {
}
}

///[initForegroundTask] initializes the foreground task
Future<bool> initForegroundTask() async {
bool isPermissionsGiven = await Utilities.getPermissions();
if (isPermissionsGiven) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,21 +505,13 @@ class HMSHLSPlayerAction {
"bitrate": 200 * 1000
],
[
"resolution": [
"height": 1080.0,
"width": 1920.0
],
"bitrate": 0
"bitrate": nil
]

]

static private var currentBitrate : Any? = [
"resolution": [
"height": 0.0,
"width": 0.0
],
"bitrate": 0
"bitrate": nil
]

static private func getHLSLayers(
Expand All @@ -540,19 +532,36 @@ class HMSHLSPlayerAction {
return
}

let bitrate = layer["bitrate"]{
/*
Here if the bitrate is nil
we set it as zero otherwise the given bitrate is applied
*/
if let bitrate = layer["bitrate"]{
currentBitrate = bitrate
NotificationCenter.default.post(
name: NSNotification.Name(
HLS_PLAYER_METHOD
),
object: nil,
userInfo: [
METHOD_CALL: "",
METHOD_CALL: "set_hls_layer",
"result": result,
"bitrate": bitrate
]
)
}else{
currentBitrate = nil
NotificationCenter.default.post(
name: NSNotification.Name(
HLS_PLAYER_METHOD
),
object: nil,
userInfo: [
METHOD_CALL: "",
"result": result,
"bitrate": 0
]
)
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@ class HMSHLSLayer {

HMSHLSLayer({this.resolution, this.bitrate});

factory HMSHLSLayer.fromMap(Map<dynamic, dynamic> map){
factory HMSHLSLayer.fromMap(Map<dynamic, dynamic> map) {
return HMSHLSLayer(
resolution: map['resolution'] != null? HMSResolution.fromMap(map['resolution']):null,
bitrate: map['bitrate']
);
resolution: map['resolution'] != null
? HMSResolution.fromMap(map['resolution'])
: null,
bitrate: map['bitrate']);
}

Map<String, dynamic> toMap(){
return {
'resolution': this.resolution?.toMap(),
'bitrate': this.bitrate
};
Map<String, dynamic> toMap() {
return {'resolution': this.resolution?.toMap(), 'bitrate': this.bitrate};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,7 @@ class HMSHLSPlayerController {

static Future<void> setHLSLayer({required HMSHLSLayer hmsHLSLayer}) async {
await PlatformService.invokeMethod(PlatformMethod.setHLSLayer,
arguments: {
"layer": hmsHLSLayer.toMap()
});
arguments: {"layer": hmsHLSLayer.toMap()});
}

static Future<HMSHLSLayer?> getCurrentHLSLayer() async {
Expand Down

0 comments on commit 0f2bc4a

Please sign in to comment.