Skip to content

Commit

Permalink
Shadowing mode subtitle offset
Browse files Browse the repository at this point in the history
  • Loading branch information
arianneorpilla committed May 3, 2021
1 parent 900aa2b commit b636e0e
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<p align="center">A mobile video player tailored for Japanese language learners.</p>

<p align="center" style="margin:0"><b>Latest GitHub Release:<br>
<a href="https://github.com/lrorpilla/jidoujisho/releases/tag/0.15.0-beta">0.15.0-beta 🇯🇵 → 🇬🇧</a><br>
<a href="https://github.com/lrorpilla/jidoujisho/releases/tag/0.15.1-beta">0.15.1-beta 🇯🇵 → 🇬🇧</a><br>
<a href="https://github.com/lrorpilla/jidoujisho/releases/tag/0.5.3-enjp-beta">0.5.3-beta 🇬🇧 → 🇯🇵</a></b><br></p>
<div latest></div>

Expand Down
2 changes: 2 additions & 0 deletions chewie/lib/src/chewie_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ class ChewieController extends ChangeNotifier {
@required this.exportSingleCallback,
@required this.toggleShadowingMode,
@required this.shadowingSubtitle,
@required this.audioAllowance,
this.aspectRatio,
this.autoInitialize = false,
this.autoPlay = false,
Expand Down Expand Up @@ -270,6 +271,7 @@ class ChewieController extends ChangeNotifier {
final VoidCallback exportSingleCallback;
final VoidCallback toggleShadowingMode;
final ValueNotifier<Subtitle> shadowingSubtitle;
final ValueNotifier<int> audioAllowance;
final YouTubeMux streamData;

/// Initialize the Video on Startup. This will prep the video for playback.
Expand Down
11 changes: 9 additions & 2 deletions chewie/lib/src/material_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -550,15 +550,22 @@ class _MaterialControlsState extends State<MaterialControls>
: Duration.zero;

if (chewieController.shadowingSubtitle.value != null) {
final shadowDuration = Duration(
milliseconds:
chewieController.shadowingSubtitle.value.endTime.inMilliseconds +
chewieController.audioAllowance.value);

return GestureDetector(
onTap: () {
chewieController.toggleShadowingMode();
},
child: Padding(
padding: const EdgeInsets.only(right: 24.0),
padding: const EdgeInsets.only(
right: 24.0,
),
child: Text(
duration != Duration.zero
? '${formatDuration(position)} / ${formatDuration(chewieController.shadowingSubtitle.value.endTime)}'
? '${formatDuration(position)} / ${formatDuration(shadowDuration)}'
: '',
style: const TextStyle(
fontSize: 14.0,
Expand Down
5 changes: 4 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2310,7 +2310,10 @@ class _ClipboardState extends State<ClipboardMenu> {
}

if (entries.isEmpty) {
return emptyMessage;
return Column(children: [
cardCreatorButton(),
Expanded(child: emptyMessage),
]);
}

return ListView.builder(
Expand Down
32 changes: 22 additions & 10 deletions lib/player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ class _VideoPlayerState extends State<VideoPlayer> {
ValueNotifier<bool> _wasPlaying = ValueNotifier<bool>(false);
ValueNotifier<bool> _widgetVisibility = ValueNotifier<bool>(false);
ValueNotifier<Subtitle> _shadowingSubtitle = ValueNotifier<Subtitle>(null);
int audioAllowance = getAudioAllowance();
ValueNotifier<int> _audioAllowance = ValueNotifier<int>(getAudioAllowance());

Timer durationTimer;
Timer visibilityTimer;
Expand Down Expand Up @@ -349,11 +349,18 @@ class _VideoPlayerState extends State<VideoPlayer> {
void visibilityTimerAction() {
if (getVideoPlayerController().value.isInitialized) {
if (_shadowingSubtitle.value != null) {
if (getVideoPlayerController().value.position >
_shadowingSubtitle.value.endTime ||
getVideoPlayerController().value.position <
_shadowingSubtitle.value.startTime - Duration(seconds: 10)) {
getVideoPlayerController().seekTo(_shadowingSubtitle.value.startTime);
if (getVideoPlayerController().value.position.inMilliseconds +
_audioAllowance.value -
getSubtitleController().subtitlesOffset <
_shadowingSubtitle.value.startTime.inMilliseconds - 10000 ||
getVideoPlayerController().value.position.inMilliseconds -
_audioAllowance.value -
getSubtitleController().subtitlesOffset >
_shadowingSubtitle.value.endTime.inMilliseconds) {
getVideoPlayerController().seekTo(Duration(
milliseconds: _shadowingSubtitle.value.startTime.inMilliseconds +
getSubtitleController().subtitlesOffset -
_audioAllowance.value));
}
}

Expand Down Expand Up @@ -509,7 +516,7 @@ class _VideoPlayerState extends State<VideoPlayer> {
_currentDictionaryEntry.value,
wasPlaying,
selection,
audioAllowance,
_audioAllowance.value,
getSubtitleController().subtitlesOffset,
);
}
Expand All @@ -527,7 +534,7 @@ class _VideoPlayerState extends State<VideoPlayer> {
_currentDictionaryEntry.value,
_wasPlaying.value,
[_currentSubtitle.value],
audioAllowance,
_audioAllowance.value,
getSubtitleController().subtitlesOffset,
);
}
Expand Down Expand Up @@ -635,6 +642,7 @@ class _VideoPlayerState extends State<VideoPlayer> {
exportSingleCallback: exportSingleCallback,
toggleShadowingMode: toggleShadowingMode,
shadowingSubtitle: _shadowingSubtitle,
audioAllowance: _audioAllowance,
streamData: streamData,
aspectRatio: getVideoPlayerController().value.aspectRatio,
autoPlay: true,
Expand Down Expand Up @@ -734,7 +742,7 @@ class _VideoPlayerState extends State<VideoPlayer> {
TextEditingController _offsetController = TextEditingController(
text: getSubtitleController().subtitlesOffset.toString());
TextEditingController _allowanceController =
TextEditingController(text: audioAllowance.toString());
TextEditingController(text: _audioAllowance.value.toString());

void setValues(bool remember) {
String offsetText = _offsetController.text;
Expand All @@ -747,7 +755,7 @@ class _VideoPlayerState extends State<VideoPlayer> {
getSubtitleController().subtitlesOffset = newOffset;
getSubtitleController().updateSubtitleContent(
content: getSubtitleController().subtitlesContent);
audioAllowance = newAllowance;
_audioAllowance.value = newAllowance;

if (remember) {
setSubtitleDelay(newOffset);
Expand Down Expand Up @@ -1334,6 +1342,10 @@ class _VideoPlayerState extends State<VideoPlayer> {
_videoPlayerController.seekTo(subtitles[index].startTime +
Duration(milliseconds: _subTitleController.subtitlesOffset));
_videoPlayerController.play();

if (_shadowingSubtitle.value != null) {
_shadowingSubtitle.value = subtitles[index];
}
},
onLongPress: () {
List<Subtitle> selectedSubtitles = [];
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: jidoujisho
description: A mobile video player tailored for Japanese language learners.
publish_to: none

version: 0.15.0+17
version: 0.15.1+18

environment:
sdk: ">=2.7.0 <3.0.0"
Expand Down

0 comments on commit b636e0e

Please sign in to comment.