From 0f2bc4ab1ba558c6c3cc5f3dcfb3fad1c81440c0 Mon Sep 17 00:00:00 2001 From: Decoder07 Date: Tue, 30 Apr 2024 14:54:15 +0530 Subject: [PATCH] Added check tick on selected layer --- .../lib/src/hls_viewer/hls_player_store.dart | 29 ++++++- ..._viewer_quality_selector_bottom_sheet.dart | 87 ++++++++++--------- .../example/lib/foreground_task_handler.dart | 6 +- .../HLSPlayer/HMSHLSPlayerAction.swift | 33 ++++--- .../src/model/hls_player/hms_hls_layer.dart | 16 ++-- .../hls_player/hms_hls_player_controller.dart | 4 +- 6 files changed, 104 insertions(+), 71 deletions(-) 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 35e2cc00e..a832fd55f 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 @@ -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'; @@ -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)); @@ -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(); @@ -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; diff --git a/packages/hms_room_kit/lib/src/widgets/bottom_sheets/hls_viewer_quality_selector_bottom_sheet.dart b/packages/hms_room_kit/lib/src/widgets/bottom_sheets/hls_viewer_quality_selector_bottom_sheet.dart index a9ae599ad..374c2cfcf 100644 --- a/packages/hms_room_kit/lib/src/widgets/bottom_sheets/hls_viewer_quality_selector_bottom_sheet.dart +++ b/packages/hms_room_kit/lib/src/widgets/bottom_sheets/hls_viewer_quality_selector_bottom_sheet.dart @@ -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( @@ -59,8 +60,7 @@ class _HLSViewerQualitySelectorBottomSheetState children: [ HMSTitleText( text: "Quality", - textColor: - HMSThemeColors.onSurfaceHighEmphasis, + textColor: HMSThemeColors.onSurfaceHighEmphasis, letterSpacing: 0.15, ), ], @@ -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() - .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().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() + .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, - ), + ), ); }), ) diff --git a/packages/hmssdk_flutter/example/lib/foreground_task_handler.dart b/packages/hmssdk_flutter/example/lib/foreground_task_handler.dart index 1648758f1..ade4caddb 100644 --- a/packages/hmssdk_flutter/example/lib/foreground_task_handler.dart +++ b/packages/hmssdk_flutter/example/lib/foreground_task_handler.dart @@ -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(key: 'customData'); - print('customData: $customData'); } // Called every [interval] milliseconds in [ForegroundTaskOptions]. @@ -51,6 +46,7 @@ class ForegroundTaskHandler extends TaskHandler { } } +///[initForegroundTask] initializes the foreground task Future initForegroundTask() async { bool isPermissionsGiven = await Utilities.getPermissions(); if (isPermissionsGiven) { diff --git a/packages/hmssdk_flutter/ios/Classes/HLSPlayer/HMSHLSPlayerAction.swift b/packages/hmssdk_flutter/ios/Classes/HLSPlayer/HMSHLSPlayerAction.swift index e36fd72a8..8cff0a809 100644 --- a/packages/hmssdk_flutter/ios/Classes/HLSPlayer/HMSHLSPlayerAction.swift +++ b/packages/hmssdk_flutter/ios/Classes/HLSPlayer/HMSHLSPlayerAction.swift @@ -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( @@ -540,7 +532,11 @@ 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( @@ -548,11 +544,24 @@ class HMSHLSPlayerAction { ), 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 + ] + ) } } diff --git a/packages/hmssdk_flutter/lib/src/model/hls_player/hms_hls_layer.dart b/packages/hmssdk_flutter/lib/src/model/hls_player/hms_hls_layer.dart index 55b4a9dc2..ec37783fd 100644 --- a/packages/hmssdk_flutter/lib/src/model/hls_player/hms_hls_layer.dart +++ b/packages/hmssdk_flutter/lib/src/model/hls_player/hms_hls_layer.dart @@ -6,17 +6,15 @@ class HMSHLSLayer { HMSHLSLayer({this.resolution, this.bitrate}); - factory HMSHLSLayer.fromMap(Map map){ + factory HMSHLSLayer.fromMap(Map 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 toMap(){ - return { - 'resolution': this.resolution?.toMap(), - 'bitrate': this.bitrate - }; + Map toMap() { + return {'resolution': this.resolution?.toMap(), 'bitrate': this.bitrate}; } } diff --git a/packages/hmssdk_flutter/lib/src/model/hls_player/hms_hls_player_controller.dart b/packages/hmssdk_flutter/lib/src/model/hls_player/hms_hls_player_controller.dart index a1897caeb..a849e0df6 100644 --- a/packages/hmssdk_flutter/lib/src/model/hls_player/hms_hls_player_controller.dart +++ b/packages/hmssdk_flutter/lib/src/model/hls_player/hms_hls_player_controller.dart @@ -159,9 +159,7 @@ class HMSHLSPlayerController { static Future setHLSLayer({required HMSHLSLayer hmsHLSLayer}) async { await PlatformService.invokeMethod(PlatformMethod.setHLSLayer, - arguments: { - "layer": hmsHLSLayer.toMap() - }); + arguments: {"layer": hmsHLSLayer.toMap()}); } static Future getCurrentHLSLayer() async {