From 8a068aaac030419e610215f51bad8334c3be740d Mon Sep 17 00:00:00 2001 From: dom Date: Sun, 14 Jun 2026 17:43:04 +0800 Subject: [PATCH] cache live stream pref Signed-off-by: dom --- lib/pages/live_room/controller.dart | 27 +++++++++++++++++++ .../live_room/widgets/header_control.dart | 10 +++++++ lib/utils/storage_key.dart | 3 ++- lib/utils/storage_pref.dart | 2 ++ 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/lib/pages/live_room/controller.dart b/lib/pages/live_room/controller.dart index 698913a6b..33f26201d 100644 --- a/lib/pages/live_room/controller.dart +++ b/lib/pages/live_room/controller.dart @@ -198,6 +198,7 @@ class LiveRoomController extends GetxController { startLiveTimer(); isPortrait.value = response.isPortrait ?? false; stream = playurl.stream; + _initStreamIndex(); await initLiveUrl( streamIndex: streamIndex, formatIndex: formatIndex, @@ -216,6 +217,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 542fb64c8..4661572f9 100644 --- a/lib/utils/storage_key.dart +++ b/lib/utils/storage_key.dart @@ -57,7 +57,8 @@ abstract final class SettingBoxKey { enableImgMenu = 'enableImgMenu', touchSlopH = 'touchSlopH', floatingNavBar = 'floatingNavBar', - angleDegrees = 'angleDegrees'; + angleDegrees = 'angleDegrees', + liveStream = 'liveStream'; static const String windowSize = 'windowSize', windowPosition = 'windowPosition', diff --git a/lib/utils/storage_pref.dart b/lib/utils/storage_pref.dart index eeeaa28e1..e45175414 100644 --- a/lib/utils/storage_pref.dart +++ b/lib/utils/storage_pref.dart @@ -553,4 +553,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); }