From d4d4b0aac21ceab04aedb78b68d50ba01a68a348 Mon Sep 17 00:00:00 2001 From: dshukertjr <18113850+dshukertjr@users.noreply.github.com> Date: Sun, 30 May 2021 20:26:50 +0900 Subject: [PATCH 1/2] Not using cache for playing video, and not looping video anymore --- lib/components/full_screen_video_player.dart | 78 ++++++++++++++++---- lib/cubits/video/video_cubit.dart | 1 - lib/repositories/repository.dart | 3 +- 3 files changed, 63 insertions(+), 19 deletions(-) diff --git a/lib/components/full_screen_video_player.dart b/lib/components/full_screen_video_player.dart index 4ae15d7..fe6ad7b 100644 --- a/lib/components/full_screen_video_player.dart +++ b/lib/components/full_screen_video_player.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:video_player/video_player.dart'; -class FullScreenVideoPlayer extends StatelessWidget { +class FullScreenVideoPlayer extends StatefulWidget { const FullScreenVideoPlayer({ Key? key, required VideoPlayerController videoPlayerController, @@ -10,32 +10,78 @@ class FullScreenVideoPlayer extends StatelessWidget { final VideoPlayerController _videoPlayerController; + @override + _FullScreenVideoPlayerState createState() => _FullScreenVideoPlayerState(); +} + +class _FullScreenVideoPlayerState extends State { @override Widget build(BuildContext context) { return GestureDetector( - onTap: () { + onTap: () async { // Toggle video play - if (_videoPlayerController.value.isPlaying) { - _videoPlayerController.pause(); + if (widget._videoPlayerController.value.isPlaying) { + await widget._videoPlayerController.pause(); } else { - _videoPlayerController.play(); + if (isVideoAtEnd) { + await widget._videoPlayerController.seekTo(Duration.zero); + } + await widget._videoPlayerController.play(); } }, - child: ClipRect( - child: OverflowBox( - alignment: Alignment.center, - child: FittedBox( - fit: BoxFit.cover, - child: SizedBox( - height: 1, - child: AspectRatio( - aspectRatio: _videoPlayerController.value.aspectRatio, - child: VideoPlayer(_videoPlayerController), + child: Stack( + fit: StackFit.expand, + children: [ + ClipRect( + child: OverflowBox( + alignment: Alignment.center, + child: FittedBox( + fit: BoxFit.cover, + child: SizedBox( + height: 1, + child: AspectRatio( + aspectRatio: widget._videoPlayerController.value.aspectRatio, + child: VideoPlayer(widget._videoPlayerController), + ), + ), ), ), ), - ), + if (!widget._videoPlayerController.value.isPlaying) + Center( + child: Material( + borderRadius: BorderRadius.circular(100), + color: const Color(0xFF000000).withOpacity(0.25), + child: const Padding( + padding: EdgeInsets.all(16.0), + child: Icon( + Icons.play_arrow, + size: 56, + ), + ), + ), + ), + ], ), ); } + + @override + void initState() { + widget._videoPlayerController.addListener(updateUi); + super.initState(); + } + + @override + void dispose() { + widget._videoPlayerController.removeListener(updateUi); + super.dispose(); + } + + void updateUi() { + setState(() {}); + } + + bool get isVideoAtEnd => + widget._videoPlayerController.value.duration == widget._videoPlayerController.value.position; } diff --git a/lib/cubits/video/video_cubit.dart b/lib/cubits/video/video_cubit.dart index 02dc962..fc45760 100644 --- a/lib/cubits/video/video_cubit.dart +++ b/lib/cubits/video/video_cubit.dart @@ -161,7 +161,6 @@ class VideoCubit extends Cubit { if (_videoPlayerController == null) { _videoPlayerController = await _repository.getVideoPlayerController(_videoDetail!.url); await _videoPlayerController!.initialize(); - await _videoPlayerController!.setLooping(true); await _videoPlayerController!.play(); emit(VideoPlaying( diff --git a/lib/repositories/repository.dart b/lib/repositories/repository.dart index 57ec4fe..98ea1d5 100644 --- a/lib/repositories/repository.dart +++ b/lib/repositories/repository.dart @@ -439,8 +439,7 @@ class Repository { } Future getVideoPlayerController(String url) async { - final file = await DefaultCacheManager().getSingleFile(url); - return VideoPlayerController.file(file); + return VideoPlayerController.network(url); } Future hasLocationPermission() async { From 0f858ced579c9520d7d32f6eed3783fd825cc3da Mon Sep 17 00:00:00 2001 From: dshukertjr <18113850+dshukertjr@users.noreply.github.com> Date: Sun, 30 May 2021 20:27:12 +0900 Subject: [PATCH 2/2] Bumped version to 1.0.12 --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 4bb11df..fe08089 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: spot description: Find local video posts -version: 1.0.11+21 +version: 1.0.12+22 publish_to: none environment: