Enable focus for video widgets

This commit is contained in:
Vishnu 2021-07-07 04:54:19 +05:30
parent b5b5bacc03
commit d3bffb41d7
2 changed files with 32 additions and 12 deletions

View file

@ -139,6 +139,10 @@ class _DetailPageState extends State<DetailPage> {
file,
autoPlay: !_hasPageChanged, // Autoplay if it was opened directly
tagPrefix: widget.config.tagPrefix,
playbackCallback: (isPlaying) {
_shouldHideAppBar = isPlaying;
_toggleFullScreen();
},
);
} else {
content = Icon(Icons.error);
@ -147,18 +151,7 @@ class _DetailPageState extends State<DetailPage> {
return GestureDetector(
onTap: () {
_shouldHideAppBar = !_shouldHideAppBar;
if (_shouldHideAppBar) {
_appBarKey.currentState.hide();
_bottomBarKey.currentState.hide();
} else {
_appBarKey.currentState.show();
_bottomBarKey.currentState.show();
}
Future.delayed(Duration.zero, () {
SystemChrome.setEnabledSystemUIOverlays(
_shouldHideAppBar ? [] : SystemUiOverlay.values,
);
});
_toggleFullScreen();
},
child: content,
);
@ -179,6 +172,21 @@ class _DetailPageState extends State<DetailPage> {
);
}
void _toggleFullScreen() {
if (_shouldHideAppBar) {
_appBarKey.currentState.hide();
_bottomBarKey.currentState.hide();
} else {
_appBarKey.currentState.show();
_bottomBarKey.currentState.show();
}
Future.delayed(Duration.zero, () {
SystemChrome.setEnabledSystemUIOverlays(
_shouldHideAppBar ? [] : SystemUiOverlay.values,
);
});
}
void _preloadEntries(int index) async {
if (index == 0 && !_hasLoadedTillStart) {
final result = await widget.config.asyncLoader(

View file

@ -17,10 +17,13 @@ class VideoWidget extends StatefulWidget {
final File file;
final bool autoPlay;
final String tagPrefix;
final Function(bool) playbackCallback;
VideoWidget(
this.file, {
this.autoPlay = false,
this.tagPrefix,
this.playbackCallback,
Key key,
}) : super(key: key);
@ -33,6 +36,7 @@ class _VideoWidgetState extends State<VideoWidget> {
VideoPlayerController _videoPlayerController;
ChewieController _chewieController;
double _progress;
bool _isPlaying;
@override
void initState() {
@ -149,6 +153,14 @@ class _VideoWidgetState extends State<VideoWidget> {
}
Widget _getVideoPlayer() {
_videoPlayerController.addListener(() {
if (_isPlaying != _videoPlayerController.value.isPlaying) {
_isPlaying = _videoPlayerController.value.isPlaying;
if (widget.playbackCallback != null) {
widget.playbackCallback(_isPlaying);
}
}
});
_chewieController = ChewieController(
videoPlayerController: _videoPlayerController,
aspectRatio: _videoPlayerController.value.aspectRatio,