Skip to content

Commit

Permalink
Merge branch 'develop' into FLUT-298
Browse files Browse the repository at this point in the history
  • Loading branch information
Decoder07 authored May 7, 2024
2 parents 23a0c97 + 8c2e658 commit f6f62c0
Show file tree
Hide file tree
Showing 22 changed files with 958 additions and 177 deletions.
2 changes: 1 addition & 1 deletion .java-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
openjdk64-17.0.10
openjdk64-17.0.11
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ class _HLSPlayerSeekbarState extends State<HLSPlayerSeekbar> {
hlsPlayerStore.timeFromLive, hlsPlayerStore.rollingWindow),
builder: (_, data, __) {
maxValue = data.item2.inSeconds;
seekBarValue = maxValue > 0 ? maxValue - data.item1.inSeconds : 0;

///We only subtract the time from live from the rolling window if the time from live is greater than 0
seekBarValue = maxValue > 0
? maxValue -
(data.item1.inSeconds > 0 ? data.item1.inSeconds : 0)
: 0;
minValue = 0;
return (maxValue > 0 && seekBarValue > 0)
? SliderTheme(
Expand Down
59 changes: 58 additions & 1 deletion 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 @@ -75,6 +76,10 @@ class HLSPlayerStore extends ChangeNotifier

String? caption;

Map<String, HMSHLSLayer> layerMap = {};

HMSHLSLayer? selectedLayer;

///This method starts a timer for 5 seconds and then hides the buttons
///
///[isStreamPlaying] is used to check if the video is playing or not
Expand Down Expand Up @@ -215,6 +220,56 @@ class HLSPlayerStore extends ChangeNotifier
notifyListeners();
}

///[getHLSLayers] gets the HLS Layers
void getHLSLayers() async {
var layers = await HMSHLSPlayerController.getHLSLayers();
int layersSize = layers.length;
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];
}
}
}

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

///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();
}

///[setHLSLayer] sets the HLS Layer
void setHLSLayer(HMSHLSLayer hmsHLSLayer) async {
selectedLayer = hmsHLSLayer;
await HMSHLSPlayerController.setHLSLayer(hmsHLSLayer: hmsHLSLayer);
notifyListeners();
}

@override
void onCue({required HMSHLSCue hlsCue}) {}

Expand All @@ -223,7 +278,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 All @@ -244,6 +299,8 @@ class HLSPlayerStore extends ChangeNotifier
areClosedCaptionsSupported();
setHLSPlayerStats(true);
startTimer();
getHLSLayers();
getCurrentHLSLayer();
isStreamPlaying = true;
isPlayerFailed = false;
break;
Expand Down
44 changes: 33 additions & 11 deletions packages/hms_room_kit/lib/src/hls_viewer/hls_viewer_header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ library;
///Package imports
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:hms_room_kit/src/meeting/meeting_store.dart';
import 'package:hms_room_kit/src/widgets/bottom_sheets/hls_viewer_quality_selector_bottom_sheet.dart';
import 'package:provider/provider.dart';

///Project imports
Expand Down Expand Up @@ -87,18 +89,38 @@ class HLSViewerHeader extends StatelessWidget {
}),

///This will be added later
// const SizedBox(
// width: 16,
// ),
const SizedBox(
width: 16,
),

// ///This renders the settings button
// SvgPicture.asset(
// "packages/hms_room_kit/lib/src/assets/icons/settings.svg",
// colorFilter: ColorFilter.mode(
// HMSThemeColors.onSurfaceHighEmphasis,
// BlendMode.srcIn),
// semanticsLabel: "caption_toggle_button",
// )
///This renders the settings button
GestureDetector(
onTap: () {
var _meetingStore =
context.read<MeetingStore>();
var _hlsPlayerStore =
context.read<HLSPlayerStore>();
showModalBottomSheet(
isScrollControlled: true,
backgroundColor: Colors.transparent,
context: context,
builder: (ctx) =>
ChangeNotifierProvider.value(
value: _meetingStore,
child: ChangeNotifierProvider.value(
value: _hlsPlayerStore,
child:
HLSViewerQualitySelectorBottomSheet()),
));
},
child: SvgPicture.asset(
"packages/hms_room_kit/lib/src/assets/icons/settings.svg",
colorFilter: ColorFilter.mode(
HMSThemeColors.onSurfaceHighEmphasis,
BlendMode.srcIn),
semanticsLabel: "caption_toggle_button",
),
)
],
)
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:hms_room_kit/src/hls_viewer/hls_player_store.dart';
import 'package:hms_room_kit/src/layout_api/hms_theme_colors.dart';
import 'package:hms_room_kit/src/meeting/meeting_store.dart';
import 'package:hms_room_kit/src/widgets/common_widgets/hms_cross_button.dart';
import 'package:hms_room_kit/src/widgets/common_widgets/hms_subtitle_text.dart';
import 'package:hms_room_kit/src/widgets/common_widgets/hms_title_text.dart';
import 'package:hmssdk_flutter/hmssdk_flutter.dart';
import 'package:provider/provider.dart';
import 'package:tuple/tuple.dart';

class HLSViewerQualitySelectorBottomSheet extends StatefulWidget {
@override
State<HLSViewerQualitySelectorBottomSheet> createState() =>
_HLSViewerQualitySelectorBottomSheetState();
}

class _HLSViewerQualitySelectorBottomSheetState
extends State<HLSViewerQualitySelectorBottomSheet> {
@override
void initState() {
super.initState();
context.read<MeetingStore>().addBottomSheet(context);
}

@override
void deactivate() {
context.read<MeetingStore>().removeBottomSheet(context);
super.deactivate();
}

@override
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,
child: Container(
decoration: BoxDecoration(
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(16), topRight: Radius.circular(16)),
color: HMSThemeColors.backgroundDefault,
),
child: Selector<HLSPlayerStore,
Tuple2<Map<String, HMSHLSLayer>, int>>(
selector: (_, hlsPlayerStore) => Tuple2(
hlsPlayerStore.layerMap, hlsPlayerStore.layerMap.length),
builder: (context, data, _) {
return Padding(
padding:
const EdgeInsets.only(top: 24.0, left: 16, right: 16),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
HMSTitleText(
text: "Quality",
textColor: HMSThemeColors.onSurfaceHighEmphasis,
letterSpacing: 0.15,
),
],
),
const Row(
children: [HMSCrossButton()],
),
],
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 16),
child: Divider(
color: HMSThemeColors.borderDefault,
height: 5,
),
),
Expanded(
child: ListView.builder(
itemCount: data.item2,
itemBuilder: (context, index) {
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,
),
),
);
}),
)
],
),
);
}),
));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package live.hms.hmssdk_flutter

import live.hms.hls_player.HmsHlsLayer

class HMSHLSLayerExtension {

companion object{
fun toDictionary(hmsHLSLayer :HmsHlsLayer?): HashMap<Any,Any?>?{

if(hmsHLSLayer == null){
return null;
}
val map = HashMap<Any,Any?>()
if(hmsHLSLayer == HmsHlsLayer.AUTO){
return map
}
(hmsHLSLayer as HmsHlsLayer.LayerInfo?)?.let {
map["resolution"] = HMSVideoResolutionExtension.toDictionary(it.resolution)
map["bitrate"] = it.bitrate
}
return map
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ class HmssdkFlutterPlugin :
"remove_key_change_listener" -> {
removeKeyChangeListener(call, result)
}
"start_hls_player", "stop_hls_player", "pause_hls_player", "resume_hls_player", "seek_to_live_position", "seek_forward", "seek_backward", "set_hls_player_volume", "add_hls_stats_listener", "remove_hls_stats_listener", "are_closed_captions_supported", "enable_closed_captions", "disable_closed_captions", "get_stream_properties" -> {
"start_hls_player", "stop_hls_player", "pause_hls_player", "resume_hls_player", "seek_to_live_position", "seek_forward", "seek_backward", "set_hls_player_volume", "add_hls_stats_listener", "remove_hls_stats_listener", "are_closed_captions_supported", "enable_closed_captions", "disable_closed_captions", "get_stream_properties","get_hls_layers", "set_hls_layer", "get_current_hls_layer" -> {
HMSHLSPlayerAction.hlsPlayerAction(call, result)
}
"toggle_always_screen_on" -> {
Expand Down
Loading

0 comments on commit f6f62c0

Please sign in to comment.