Skip to content

Commit

Permalink
Fixed preview audio issue and orientation not returning to portrait a…
Browse files Browse the repository at this point in the history
…fter video playback, UI changes while loading
  • Loading branch information
arianneorpilla committed Apr 4, 2021
1 parent 9b7cc5d commit 973991b
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 29 deletions.
32 changes: 22 additions & 10 deletions chewie-0.12.2/lib/src/material_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,21 @@ class _MaterialControlsState extends State<MaterialControls>
}

Expanded _buildHitArea() {
final bool isFinished = _latestValue.position >= _latestValue.duration;
Widget getIcon() {
if (_latestValue.isEnded) {
return const Icon(Icons.replay, size: 32.0);
} else {
if (!_latestValue.isInitialized) {
return const Icon(Icons.play_arrow, color: Colors.transparent);
}

return AnimatedIcon(
icon: AnimatedIcons.play_pause,
progress: playPauseIconAnimationController,
size: 32.0,
);
}
}

return Expanded(
child: GestureDetector(
Expand Down Expand Up @@ -211,19 +225,15 @@ class _MaterialControlsState extends State<MaterialControls>
child: GestureDetector(
child: Container(
decoration: BoxDecoration(
color: Theme.of(context).dialogBackgroundColor,
color: (_latestValue.isInitialized)
? Theme.of(context).dialogBackgroundColor
: Colors.transparent,
borderRadius: BorderRadius.circular(48.0),
),
child: Padding(
padding: const EdgeInsets.all(12.0),
child: IconButton(
icon: isFinished
? const Icon(Icons.replay, size: 32.0)
: AnimatedIcon(
icon: AnimatedIcons.play_pause,
progress: playPauseIconAnimationController,
size: 32.0,
),
icon: getIcon(),
onPressed: () {
_playPause();
}),
Expand Down Expand Up @@ -399,7 +409,9 @@ class _MaterialControlsState extends State<MaterialControls>
return Padding(
padding: const EdgeInsets.only(right: 24.0),
child: Text(
'${formatDuration(position)} / ${formatDuration(duration)}',
duration != Duration.zero
? '${formatDuration(position)} / ${formatDuration(duration)}'
: '',
style: const TextStyle(
fontSize: 14.0,
),
Expand Down
8 changes: 7 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'dart:io';

import 'package:async/async.dart';
import 'package:gx_file_picker/gx_file_picker.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:fuzzy/fuzzy.dart';
Expand Down Expand Up @@ -111,6 +110,13 @@ class _HomeState extends State<Home> {

@override
Widget build(BuildContext context) {
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]);

return new WillPopScope(
onWillPop: _onWillPop,
child: new Scaffold(
Expand Down
17 changes: 11 additions & 6 deletions lib/player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_vlc_player/flutter_vlc_player.dart';
import 'package:http/http.dart' as http;
import 'package:jidoujisho/main.dart';
import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';
import 'package:subtitle_wrapper_package/data/models/style/subtitle_style.dart';
import 'package:subtitle_wrapper_package/data/models/subtitle.dart';
Expand All @@ -25,11 +24,6 @@ class Player extends StatelessWidget {

@override
Widget build(BuildContext context) {
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]);

SystemChrome.setEnabledSystemUIOverlays([]);
Wakelock.enable();

Expand All @@ -54,6 +48,10 @@ class Player extends StatelessWidget {
File videoFile = snapshot.data;
print("VIDEO FILE: ${videoFile.path}");

if (videoFile == null) {
Navigator.pop(context);
}

return FutureBuilder(
future: extractSubtitles(videoFile),
builder:
Expand Down Expand Up @@ -335,6 +333,13 @@ class _VideoPlayerState extends State<VideoPlayer> {
Wakelock.disable();
Navigator.pop(context);
Navigator.pop(context);

SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]);
},
),
],
Expand Down
6 changes: 3 additions & 3 deletions lib/util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,9 @@ void showAnkiDialog(
_meaningController,
);

AudioPlayer audioPlayer = AudioPlayer();
imageCache.clear();

showDialog(
context: context,
builder: (context) {
Expand Down Expand Up @@ -304,9 +307,6 @@ void showAnkiDialog(
),
),
onPressed: () async {
AudioPlayer audioPlayer = AudioPlayer();
imageCache.clear();

await audioPlayer.stop();
await audioPlayer.play(previewAudioDir, isLocal: true);
},
Expand Down
14 changes: 7 additions & 7 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.3"
file_picker:
dependency: "direct main"
description:
name: file_picker
url: "https://pub.dartlang.org"
source: hosted
version: "1.10.0"
file_utils:
dependency: "direct main"
description:
Expand Down Expand Up @@ -207,6 +200,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.1"
gx_file_picker:
dependency: "direct main"
description:
name: gx_file_picker
url: "https://pub.dartlang.org"
source: hosted
version: "1.9.0+2"
html:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: A mobile video player tailored for Japanese language learners.

publish_to: none

version: 0.6.0+beta
version: 0.6.1+beta

environment:
sdk: ">=2.7.0 <3.0.0"
Expand Down
2 changes: 1 addition & 1 deletion subtitle_wrapper_package-1.0.4/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ packages:
name: pedantic
url: "https://pub.dartlang.org"
source: hosted
version: "1.10.0-nullsafety.3"
version: "1.11.0"
platform:
dependency: transitive
description:
Expand Down

0 comments on commit 973991b

Please sign in to comment.