diff --git a/lib/pages/live_room/controller.dart b/lib/pages/live_room/controller.dart index 2e42b4dda..79dff6092 100644 --- a/lib/pages/live_room/controller.dart +++ b/lib/pages/live_room/controller.dart @@ -209,6 +209,7 @@ class LiveRoomController extends GetxController { startLiveTimer(); isPortrait.value = response.isPortrait ?? false; stream = playurl.stream; + _initStreamIndex(); await initLiveUrl( streamIndex: streamIndex, formatIndex: formatIndex, @@ -227,6 +228,32 @@ class LiveRoomController extends GetxController { int codecIndex = 0; int liveUrlIndex = 0; + void _initStreamIndex() { + final pref = Pref.liveStream; + if (pref != null) { + try { + final protocolName = pref[0]; + final formatName = pref[1]; + final codecName = pref[2]; + for (var i in stream.indexed) { + if (i.$2.protocolName == protocolName) { + streamIndex = i.$1; + for (var j in i.$2.format.indexed) { + if (j.$2.formatName == formatName) { + formatIndex = j.$1; + for (var k in j.$2.codec.indexed) { + if (k.$2.codecName == codecName) { + codecIndex = k.$1; + } + } + } + } + } + } + } catch (_) {} + } + } + Future? initLiveUrl({ int streamIndex = 0, int formatIndex = 0, diff --git a/lib/pages/live_room/widgets/header_control.dart b/lib/pages/live_room/widgets/header_control.dart index 43e0ef7b2..e19817126 100644 --- a/lib/pages/live_room/widgets/header_control.dart +++ b/lib/pages/live_room/widgets/header_control.dart @@ -18,6 +18,8 @@ import 'package:PiliPlus/utils/extension/context_ext.dart'; import 'package:PiliPlus/utils/extension/size_ext.dart'; import 'package:PiliPlus/utils/extension/string_ext.dart'; import 'package:PiliPlus/utils/platform_utils.dart'; +import 'package:PiliPlus/utils/storage.dart'; +import 'package:PiliPlus/utils/storage_key.dart'; import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:get/get.dart'; @@ -432,6 +434,14 @@ class _LiveHeaderControlState extends State codecIndex: codec.$1, liveUrlIndex: url.$1, ); + GStorage.setting.put( + SettingBoxKey.liveStream, + [ + stream.$2.protocolName, + format.$2.formatName, + codec.$2.codecName, + ], + ); }, ); }).toList(), diff --git a/lib/utils/storage_key.dart b/lib/utils/storage_key.dart index 7c1f935fa..7b9eb1d74 100644 --- a/lib/utils/storage_key.dart +++ b/lib/utils/storage_key.dart @@ -155,7 +155,8 @@ abstract final class SettingBoxKey { touchSlopH = 'touchSlopH', floatingNavBar = 'floatingNavBar', removeSafeArea = 'removeSafeArea', - angleDegrees = 'angleDegrees'; + angleDegrees = 'angleDegrees', + liveStream = 'liveStream'; static const String minimizeOnExit = 'minimizeOnExit', windowSize = 'windowSize', diff --git a/lib/utils/storage_pref.dart b/lib/utils/storage_pref.dart index bba1e4698..0511a0756 100644 --- a/lib/utils/storage_pref.dart +++ b/lib/utils/storage_pref.dart @@ -1014,4 +1014,6 @@ abstract final class Pref { static double get maxVolume => // desktop _setting.get(SettingBoxKey.maxVolume, defaultValue: 2.0); + + static List? get liveStream => _setting.get(SettingBoxKey.liveStream); }