optimize native player with immediate latency, auto seek-to-live-edge, and app resume recovery
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
418c51ce6d
commit
6e5da0bae0
2 changed files with 31 additions and 22 deletions
|
|
@ -225,29 +225,37 @@ abstract class NativeVideoStoreBase with Store implements VideoPlayerInterface {
|
||||||
if (settingsStore.autoSyncChatDelay) {
|
if (settingsStore.autoSyncChatDelay) {
|
||||||
settingsStore.syncedChatDelay = 0;
|
settingsStore.syncedChatDelay = 0;
|
||||||
}
|
}
|
||||||
|
_pollLatency();
|
||||||
_latencyTimer = Timer.periodic(
|
_latencyTimer = Timer.periodic(
|
||||||
const Duration(seconds: 10),
|
const Duration(seconds: 10),
|
||||||
(_) async {
|
(_) => _pollLatency(),
|
||||||
final seconds = await _controller?.getLatencyToLive();
|
|
||||||
if (seconds == null) return;
|
|
||||||
final rounded = seconds.round();
|
|
||||||
|
|
||||||
runInAction(() {
|
|
||||||
_latency = '${rounded}s';
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!settingsStore.autoSyncChatDelay) return;
|
|
||||||
|
|
||||||
// Only update when unset or drifted by >2s to avoid restarting
|
|
||||||
// the chat countdown on minor fluctuations.
|
|
||||||
final current = settingsStore.syncedChatDelay;
|
|
||||||
if (current == 0 || (seconds - current).abs() > 2) {
|
|
||||||
settingsStore.syncedChatDelay = seconds;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _pollLatency() async {
|
||||||
|
final seconds = await _controller?.getLatencyToLive();
|
||||||
|
if (seconds == null) return;
|
||||||
|
final rounded = seconds.round();
|
||||||
|
|
||||||
|
runInAction(() {
|
||||||
|
_latency = '${rounded}s';
|
||||||
|
});
|
||||||
|
|
||||||
|
// Auto seek to live edge if we've drifted too far.
|
||||||
|
if (seconds > 15) {
|
||||||
|
await _controller?.seekToLiveEdge();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!settingsStore.autoSyncChatDelay) return;
|
||||||
|
|
||||||
|
// Only update when unset or drifted by >2s to avoid restarting
|
||||||
|
// the chat countdown on minor fluctuations.
|
||||||
|
final current = settingsStore.syncedChatDelay;
|
||||||
|
if (current == 0 || (seconds - current).abs() > 2) {
|
||||||
|
settingsStore.syncedChatDelay = seconds;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void _scheduleOverlayHide([Duration delay = const Duration(seconds: 5)]) {
|
void _scheduleOverlayHide([Duration delay = const Duration(seconds: 5)]) {
|
||||||
_overlayTimer?.cancel();
|
_overlayTimer?.cancel();
|
||||||
|
|
||||||
|
|
@ -428,9 +436,10 @@ abstract class NativeVideoStoreBase with Store implements VideoPlayerInterface {
|
||||||
@override
|
@override
|
||||||
@action
|
@action
|
||||||
void handleAppResume() {
|
void handleAppResume() {
|
||||||
if (!settingsStore.showVideo) {
|
updateStreamInfo(forceUpdate: true);
|
||||||
updateStreamInfo(forceUpdate: true);
|
// Re-check latency immediately — the stream may have drifted or died
|
||||||
}
|
// while backgrounded. If latency > 15s, _pollLatency auto-seeks to live edge.
|
||||||
|
_pollLatency();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
||||||
|
|
@ -102,7 +102,7 @@ packages:
|
||||||
description:
|
description:
|
||||||
path: "."
|
path: "."
|
||||||
ref: frosty-patches
|
ref: frosty-patches
|
||||||
resolved-ref: e16914aff5ea8a0f5bc038eb706764738f2a99c9
|
resolved-ref: "90b262e9f0d5df797918128e9a277daab57bc814"
|
||||||
url: "https://github.com/tommyxchow/flutter-native-video-player.git"
|
url: "https://github.com/tommyxchow/flutter-native-video-player.git"
|
||||||
source: git
|
source: git
|
||||||
version: "0.4.11"
|
version: "0.4.11"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue