fix: seek time overflow

This commit is contained in:
edde746
2025-11-04 08:02:00 +01:00
parent ca576110b8
commit f0035d1335
2 changed files with 38 additions and 20 deletions
+19 -12
View File
@@ -266,8 +266,7 @@ class _PlexVideoControlsState extends State<PlexVideoControls>
void _seekToPreviousChapter() {
if (_chapters.isEmpty) {
// No chapters - seek backward 10 seconds
final currentPosition = widget.player.state.position;
widget.player.seek(currentPosition - const Duration(seconds: 10));
_seekWithClamping(const Duration(seconds: -10));
return;
}
@@ -290,8 +289,7 @@ class _PlexVideoControlsState extends State<PlexVideoControls>
void _seekToNextChapter() {
if (_chapters.isEmpty) {
// No chapters - seek forward 10 seconds
final currentPosition = widget.player.state.position;
widget.player.seek(currentPosition + const Duration(seconds: 10));
_seekWithClamping(const Duration(seconds: 10));
return;
}
@@ -307,6 +305,21 @@ class _PlexVideoControlsState extends State<PlexVideoControls>
}
}
/// Seeks by the given offset (can be positive or negative) while clamping
/// the result between 0 and the video duration
void _seekWithClamping(Duration offset) {
final currentPosition = widget.player.state.position;
final duration = widget.player.state.duration;
final newPosition = currentPosition + offset;
// Clamp between 0 and video duration
final clampedPosition = newPosition.isNegative
? Duration.zero
: (newPosition > duration ? duration : newPosition);
widget.player.seek(clampedPosition);
}
Future<void> _toggleFullscreen() async {
if (!PlatformDetector.isMobile(context)) {
// Query actual window state to determine what action to take
@@ -554,10 +567,7 @@ class _PlexVideoControlsState extends State<PlexVideoControls>
),
iconSize: 48,
onPressed: () {
final currentPosition = widget.player.state.position;
widget.player.seek(
currentPosition - const Duration(seconds: 10),
);
_seekWithClamping(const Duration(seconds: -10));
},
),
),
@@ -599,10 +609,7 @@ class _PlexVideoControlsState extends State<PlexVideoControls>
),
iconSize: 48,
onPressed: () {
final currentPosition = widget.player.state.position;
widget.player.seek(
currentPosition + const Duration(seconds: 10),
);
_seekWithClamping(const Duration(seconds: 10));
},
),
),