Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 0.0.4

- Fixed: holding arrow keys on seek bar now works (was frozen due to unhandled `KeyRepeatEvent`)
- Changed seek from percentage-based (1%/press) to duration-based (`seekBarSeekDuration`, default 10s)
- Added accelerating seek on sustained hold (1x → 6x, resets on release)
- Added `seekBarSeekDuration` to `MaterialTvVideoControlsThemeData` for configurable base seek step

## 0.0.3

- Updated README
Expand Down
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var tvThemeData = MaterialTvVideoControlsThemeData(
visibleOnMount: true,
seekBarThumbColor: seekBarColor,
seekBarPositionColor: seekBarColor,
seekBarSeekDuration: Duration(seconds: 10), // base seek step per arrow press
primaryButtonBar: [
const MaterialTvPlayOrPauseButton(
iconSize: 124,
Expand All @@ -48,4 +49,14 @@ return MaterialTvVideoControlsTheme(
),
),
);
```
```

### Seek bar behavior

The seek bar uses **duration-based** seeking instead of percentage-based:

- **Tap** arrow key: seeks by `seekBarSeekDuration` (default: 10 seconds)
- **Hold** arrow key: accelerates progressively — 1x → 2x → 3x → 4x → 5x → 6x (every 4 repeats)
- **Release**: resets acceleration

This gives consistent seek UX regardless of content length (unlike percentage-based seeking where 1% of a 3-hour movie is 108 seconds).
64 changes: 47 additions & 17 deletions lib/material_tv.dart
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ class MaterialTvVideoControlsThemeData {
/// Whether to shift the subtitles upwards when the controls are visible.
final bool shiftSubtitlesOnControlsVisibilityChange;

/// Base seek step when pressing arrow keys on the seek bar.
/// Acceleration multiplies this on sustained hold. Default: 10 seconds.
final Duration seekBarSeekDuration;

/// {@macro material_desktop_video_controls_theme_data}
const MaterialTvVideoControlsThemeData({
this.displaySeekBar = true,
Expand Down Expand Up @@ -228,6 +232,7 @@ class MaterialTvVideoControlsThemeData {
this.volumeBarThumbColor = const Color(0xFFFFFFFF),
this.volumeBarTransitionDuration = const Duration(milliseconds: 150),
this.shiftSubtitlesOnControlsVisibilityChange = true,
this.seekBarSeekDuration = const Duration(seconds: 10),
});

/// Creates a copy of this [MaterialTvVideoControlsThemeData] with the given fields replaced by the non-null parameter values.
Expand Down Expand Up @@ -269,6 +274,7 @@ class MaterialTvVideoControlsThemeData {
Color? volumeBarThumbColor,
Duration? volumeBarTransitionDuration,
bool? shiftSubtitlesOnControlsVisibilityChange,
Duration? seekBarSeekDuration,
}) {
return MaterialTvVideoControlsThemeData(
displaySeekBar: displaySeekBar ?? this.displaySeekBar,
Expand Down Expand Up @@ -323,6 +329,8 @@ class MaterialTvVideoControlsThemeData {
shiftSubtitlesOnControlsVisibilityChange:
shiftSubtitlesOnControlsVisibilityChange ??
this.shiftSubtitlesOnControlsVisibilityChange,
seekBarSeekDuration:
seekBarSeekDuration ?? this.seekBarSeekDuration,
);
}
}
Expand Down Expand Up @@ -768,6 +776,15 @@ class MaterialTvSeekBarState extends State<MaterialTvSeekBar> {
late Duration duration = controller(context).player.state.duration;
late Duration buffer = controller(context).player.state.buffer;

/// Tracks consecutive repeat events for seek acceleration.
int _seekRepeatCount = 0;

/// Maximum acceleration multiplier (caps at 6x base seek duration).
static const int _maxAccelMultiplier = 6;

/// Number of repeats before each acceleration tier kicks in.
static const int _accelThreshold = 4;

final List<StreamSubscription> subscriptions = [];

@override
Expand Down Expand Up @@ -911,25 +928,38 @@ class MaterialTvSeekBarState extends State<MaterialTvSeekBar> {
child: Focus(
focusNode: focusNode2,
onKeyEvent: (node, event) {
if (event is KeyDownEvent) {
if (event.logicalKey == LogicalKeyboardKey.arrowRight) {
double percent = 0.01;

double sliderPercent =
(positionPercent + percent).clamp(0.0, 1.0);

setState(() {
hover = true;
slider = sliderPercent;
});
controller(context).player.seek(duration * slider);

// Reset acceleration on key release.
if (event is KeyUpEvent) {
if (event.logicalKey == LogicalKeyboardKey.arrowRight ||
event.logicalKey == LogicalKeyboardKey.arrowLeft) {
_seekRepeatCount = 0;
return KeyEventResult.handled;
} else if (event.logicalKey == LogicalKeyboardKey.arrowLeft) {
double percent = 0.01;
}
}

double sliderPercent =
(positionPercent - percent).clamp(0.0, 1.0);
if (event is KeyDownEvent || event is KeyRepeatEvent) {
if (event.logicalKey == LogicalKeyboardKey.arrowRight ||
event.logicalKey == LogicalKeyboardKey.arrowLeft) {
final direction =
event.logicalKey == LogicalKeyboardKey.arrowRight ? 1 : -1;

// Accelerate: multiplier grows every _accelThreshold repeats.
final multiplier = (1 + _seekRepeatCount ~/ _accelThreshold)
.clamp(1, _maxAccelMultiplier);
_seekRepeatCount++;

final baseSeek = _theme(context).seekBarSeekDuration;
final seekMs = baseSeek.inMilliseconds * multiplier;
final durationMs = duration.inMilliseconds;
if (durationMs <= 0) return KeyEventResult.handled;

final stepPercent = seekMs / durationMs;
// On first press use the player's actual position; on
// subsequent repeats use the slider target — the player
// hasn't caught up yet and would reset the seek.
final base = _seekRepeatCount <= 1 ? positionPercent : slider;
final sliderPercent =
(base + direction * stepPercent).clamp(0.0, 1.0);

setState(() {
hover = true;
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: media_kit_tv
description: "Extensions for the Flutter media_kit libary for TVs"
version: 0.0.3
version: 0.0.4
homepage: https://github.com/OpenMediaStation/media_kit_tv

environment:
Expand Down
Loading