Skip to content

Commit

Permalink
feat: add step forward and step backward
Browse files Browse the repository at this point in the history
  • Loading branch information
nini22P committed Feb 23, 2025
1 parent a463d5f commit 34457db
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/hooks/use_fvp_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,16 @@ FvpPlayer useFvpPlayer(BuildContext context) {
: await controller.seekTo(newPosition);
}

Future<void> stepBackward() async {
await controller.step(frames: -1);
logger('Step backward');
}

Future<void> stepForward() async {
await controller.step(frames: 1);
logger('Step forward');
}

Future<void> saveProgress() async {
if (file != null && duration != Duration.zero) {
if (Platform.isAndroid && file.uri.startsWith('content://')) {
Expand Down Expand Up @@ -296,6 +306,8 @@ FvpPlayer useFvpPlayer(BuildContext context) {
seekTo(Duration(seconds: position.inSeconds - seconds)),
forward: (seconds) =>
seekTo(Duration(seconds: position.inSeconds + seconds)),
stepBackward: stepBackward,
stepForward: stepForward,
updateRate: (value) => controller.setPlaybackSpeed(value),
seekTo: seekTo,
saveProgress: saveProgress,
Expand Down
18 changes: 18 additions & 0 deletions lib/hooks/use_media_kit_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,22 @@ MediaKitPlayer useMediaKitPlayer(BuildContext context) {
await seekTo(Duration(seconds: position.value.inSeconds + seconds));
}

Future<void> stepBackward() async {
final nativePlayer = player.platform;
if (nativePlayer is NativePlayer) {
await nativePlayer.command(['frame-back-step']);
logger('Step backward');
}
}

Future<void> stepForward() async {
final nativePlayer = player.platform;
if (nativePlayer is NativePlayer) {
await nativePlayer.command(['frame-step']);
logger('Step forward');
}
}

Future<void> updateRate(double value) async =>
player.state.rate == value ? null : await player.setRate(value);

Expand Down Expand Up @@ -321,6 +337,8 @@ MediaKitPlayer useMediaKitPlayer(BuildContext context) {
pause: pause,
backward: backward,
forward: forward,
stepBackward: stepBackward,
stepForward: stepForward,
updateRate: updateRate,
seekTo: seekTo,
);
Expand Down
8 changes: 8 additions & 0 deletions lib/models/player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class MediaPlayer {
final Future<void> Function() pause;
final Future<void> Function(int) backward;
final Future<void> Function(int) forward;
final Future<void> Function() stepBackward;
final Future<void> Function() stepForward;
final Future<void> Function(double) updateRate;
final Future<void> Function(Duration) seekTo;

Expand All @@ -45,6 +47,8 @@ class MediaPlayer {
required this.pause,
required this.backward,
required this.forward,
required this.stepBackward,
required this.stepForward,
required this.updateRate,
required this.seekTo,
});
Expand Down Expand Up @@ -83,6 +87,8 @@ class MediaKitPlayer extends MediaPlayer {
required super.pause,
required super.backward,
required super.forward,
required super.stepBackward,
required super.stepForward,
required super.updateRate,
required super.seekTo,
});
Expand Down Expand Up @@ -113,6 +119,8 @@ class FvpPlayer extends MediaPlayer {
required super.pause,
required super.backward,
required super.forward,
required super.stepBackward,
required super.stepForward,
required super.updateRate,
required super.seekTo,
});
Expand Down
6 changes: 6 additions & 0 deletions lib/pages/player/iris_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,12 @@ class IrisPlayer extends HookWidget {
showControl();
await useUiStore().toggleIsAlwaysOnTop();
break;
case LogicalKeyboardKey.equal:
await player.stepForward();
break;
case LogicalKeyboardKey.minus:
await player.stepBackward();
break;
default:
break;
}
Expand Down

0 comments on commit 34457db

Please sign in to comment.