diff --git a/lib/ui/detail_page.dart b/lib/ui/detail_page.dart index e90d424c6..03bdaa345 100644 --- a/lib/ui/detail_page.dart +++ b/lib/ui/detail_page.dart @@ -30,6 +30,7 @@ class _DetailPageState extends State { List _files; PageController _pageController; int _selectedIndex = 0; + bool _hasPageChanged = false; @override void initState() { @@ -75,7 +76,10 @@ class _DetailPageState extends State { }, ); } else if (file.fileType == FileType.video) { - content = VideoWidget(file); + content = VideoWidget( + file, + autoPlay: !_hasPageChanged, // Autoplay if it was opened directly + ); } else { content = Icon(Icons.error); } @@ -85,6 +89,7 @@ class _DetailPageState extends State { onPageChanged: (index) { setState(() { _selectedIndex = index; + _hasPageChanged = true; }); _preloadFiles(index); }, diff --git a/lib/ui/video_widget.dart b/lib/ui/video_widget.dart index 4c2df9d53..bbfbb39af 100644 --- a/lib/ui/video_widget.dart +++ b/lib/ui/video_widget.dart @@ -9,7 +9,8 @@ import 'loading_widget.dart'; class VideoWidget extends StatefulWidget { final File file; - VideoWidget(this.file, {Key key}) : super(key: key); + final bool autoPlay; + VideoWidget(this.file, {this.autoPlay = false, Key key}) : super(key: key); @override _VideoWidgetState createState() => _VideoWidgetState(); @@ -59,7 +60,7 @@ class _VideoWidgetState extends State { _chewieController = ChewieController( videoPlayerController: _videoPlayerController, aspectRatio: _videoPlayerController.value.aspectRatio, - autoPlay: true, + autoPlay: widget.autoPlay, autoInitialize: true, looping: true, allowFullScreen: false,