-
-
Notifications
You must be signed in to change notification settings - Fork 164
feat: hotkey for subtitle offset #1067
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import 'package:flutter/material.dart'; | ||
|
|
||
| import 'package:async/async.dart'; | ||
| import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
| import 'package:iconsax_plus/iconsax_plus.dart'; | ||
|
|
||
| import 'package:fladder/providers/settings/video_player_settings_provider.dart'; | ||
|
|
||
| class VideoPlayerSubtitleOffsetIndicator extends ConsumerStatefulWidget { | ||
| const VideoPlayerSubtitleOffsetIndicator({super.key}); | ||
|
|
||
| @override | ||
| ConsumerState<ConsumerStatefulWidget> createState() => _VideoPlayerSubtitleOffsetIndicatorState(); | ||
| } | ||
|
|
||
| class _VideoPlayerSubtitleOffsetIndicatorState extends ConsumerState<VideoPlayerSubtitleOffsetIndicator> { | ||
| late Duration currentOffset = ref.read(subtitleTimingOffsetProvider); | ||
|
|
||
| bool showIndicator = false; | ||
| late final timer = RestartableTimer(const Duration(seconds: 1), () { | ||
| setState(() { | ||
| showIndicator = false; | ||
| }); | ||
| }); | ||
|
|
||
| @override | ||
| void dispose() { | ||
| showIndicator = false; | ||
| timer.cancel(); | ||
| super.dispose(); | ||
| } | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| ref.listen( | ||
| subtitleTimingOffsetProvider, | ||
| (previous, next) { | ||
| if (previous == next) return; | ||
| setState(() { | ||
| showIndicator = true; | ||
| currentOffset = next; | ||
| }); | ||
| timer.reset(); | ||
| }, | ||
| ); | ||
|
|
||
| return IgnorePointer( | ||
| child: AnimatedOpacity( | ||
| duration: const Duration(milliseconds: 250), | ||
| opacity: showIndicator ? 1 : 0, | ||
| child: Center( | ||
| child: Container( | ||
| decoration: BoxDecoration( | ||
| color: Colors.black.withValues(alpha: 0.85), | ||
| borderRadius: BorderRadius.circular(16), | ||
| ), | ||
| child: Padding( | ||
| padding: const EdgeInsets.all(16.0), | ||
| child: Row( | ||
| mainAxisSize: MainAxisSize.min, | ||
| spacing: 12, | ||
| children: [ | ||
| const Icon(IconsaxPlusLinear.textalign_left), | ||
| Text(_subtitleDelayLabel(currentOffset)), | ||
| ], | ||
| ), | ||
| ), | ||
| ), | ||
| ), | ||
| ), | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| String _subtitleDelayLabel(Duration offset) { | ||
| final absMilliseconds = offset.inMilliseconds.abs(); | ||
| final sign = offset.inMilliseconds >= 0 ? '+' : '-'; | ||
| return 'Subtitle $sign${absMilliseconds}ms'; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should also be translated |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,7 @@ import 'package:fladder/screens/video_player/components/video_player_quality_con | |
| import 'package:fladder/screens/video_player/components/video_player_screenshot_indicator.dart'; | ||
| import 'package:fladder/screens/video_player/components/video_player_seek_indicator.dart'; | ||
| import 'package:fladder/screens/video_player/components/video_player_speed_indicator.dart'; | ||
| import 'package:fladder/screens/video_player/components/video_player_subtitle_offset_indicator.dart'; | ||
| import 'package:fladder/screens/video_player/components/video_player_volume_indicator.dart'; | ||
| import 'package:fladder/screens/video_player/components/video_progress_bar.dart'; | ||
| import 'package:fladder/screens/video_player/components/video_volume_slider.dart'; | ||
|
|
@@ -182,6 +183,7 @@ class _DesktopControlsState extends ConsumerState<DesktopControls> { | |
| ), | ||
| VideoPlayerSeekIndicator(controller: _seekController), | ||
| const VideoPlayerVolumeIndicator(), | ||
| const VideoPlayerSubtitleOffsetIndicator(), | ||
| const VideoPlayerBrightnessIndicator(), | ||
| const VideoPlayerSpeedIndicator(), | ||
| const VideoPlayerScreenshotIndicator(), | ||
|
|
@@ -1000,6 +1002,8 @@ class _DesktopControlsState extends ConsumerState<DesktopControls> { | |
| final mediaSegments = ref.read(playBackModel.select((value) => value?.mediaSegments)); | ||
| final position = ref.read(mediaPlaybackProvider).position; | ||
| final playing = ref.read(mediaPlaybackProvider.select((value) => value.playing)); | ||
| final subtitlesEnabled = ref.read(playBackModel)?.mediaStreams?.defaultSubStreamIndex != null && | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could just show the subtitle offset always, not sure we have to hide it if nothing is selected. |
||
| ref.read(playBackModel)!.mediaStreams!.defaultSubStreamIndex != -1; | ||
|
|
||
| MediaSegment? segment = mediaSegments?.atPosition(position); | ||
|
|
||
|
|
@@ -1064,6 +1068,16 @@ class _DesktopControlsState extends ConsumerState<DesktopControls> { | |
| case VideoHotKeys.toggleSubtitles: | ||
| _toggleSubtitles(); | ||
| return true; | ||
| case VideoHotKeys.subtitleOffsetBackward: | ||
| if (!subtitlesEnabled) return false; | ||
| ref.read(subtitleTimingOffsetProvider.notifier).update((state) => state + const Duration(milliseconds: -250)); | ||
| ref.read(videoPlayerProvider).shiftSubtitleOffset(const Duration(milliseconds: -250)); | ||
| return true; | ||
| case VideoHotKeys.subtitleOffsetForward: | ||
| if (!subtitlesEnabled) return false; | ||
| ref.read(subtitleTimingOffsetProvider.notifier).update((state) => state + const Duration(milliseconds: 250)); | ||
| ref.read(videoPlayerProvider).shiftSubtitleOffset(const Duration(milliseconds: 250)); | ||
| return true; | ||
| case VideoHotKeys.seekForwardInstant: | ||
| final seekForwardSeconds = | ||
| ref.read(userProvider.select((value) => value?.userSettings?.skipForwardDuration.inSeconds ?? 30)); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should be localized in the app_en.arb base translations file.