diff --git a/example/macos/Flutter/GeneratedPluginRegistrant.swift b/example/macos/Flutter/GeneratedPluginRegistrant.swift index a44eb02f..e03197c4 100644 --- a/example/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/example/macos/Flutter/GeneratedPluginRegistrant.swift @@ -5,7 +5,7 @@ import FlutterMacOS import Foundation -import path_provider_macos +import path_provider_foundation import wakelock_macos func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { diff --git a/lib/src/manager/flick_manager.dart b/lib/src/manager/flick_manager.dart index fcf874cb..baceb6f6 100644 --- a/lib/src/manager/flick_manager.dart +++ b/lib/src/manager/flick_manager.dart @@ -62,12 +62,18 @@ class FlickManager { /// /// Current playing video will be paused and disposed, /// if [videoChangeDuration] is passed video change will happen after that duration. - handleChangeVideo(VideoPlayerController videoPlayerController, - {Duration? videoChangeDuration, - TimerCancelCallback? timerCancelCallback}) { - _flickVideoManager!._handleChangeVideo(videoPlayerController, - videoChangeDuration: videoChangeDuration, - timerCancelCallback: timerCancelCallback); + handleChangeVideo( + VideoPlayerController videoPlayerController, { + Duration? videoChangeDuration, + TimerCancelCallback? timerCancelCallback, + Duration? startFrom, + }) { + _flickVideoManager!._handleChangeVideo( + videoPlayerController, + videoChangeDuration: videoChangeDuration, + timerCancelCallback: timerCancelCallback, + startFrom: startFrom, + ); } _handleToggleFullscreen() { diff --git a/lib/src/manager/video_manager.dart b/lib/src/manager/video_manager.dart index 7879c02d..846d3369 100644 --- a/lib/src/manager/video_manager.dart +++ b/lib/src/manager/video_manager.dart @@ -81,14 +81,17 @@ class FlickVideoManager extends ChangeNotifier { _notify(); } - _handleChangeVideo(VideoPlayerController newController, - {Duration? videoChangeDuration, - TimerCancelCallback? timerCancelCallback}) async { + _handleChangeVideo( + VideoPlayerController newController, { + Duration? videoChangeDuration, + TimerCancelCallback? timerCancelCallback, + Duration? startFrom, + }) async { // If videoChangeDuration is not null, start the autoPlayTimer. if (videoChangeDuration != null) { _timerCancelCallback = timerCancelCallback; _videoChangeCallback = () { - _changeVideo(newController); + _changeVideo(newController, startFrom: startFrom); _nextVideoAutoPlayTimer = null; _nextVideoAutoPlayDuration = null; _videoChangeCallback = null; @@ -101,12 +104,15 @@ class FlickVideoManager extends ChangeNotifier { _notify(); } else { // If videoChangeDuration is null, directly change the video. - _changeVideo(newController); + _changeVideo(newController, startFrom: startFrom); } } // Immediately change the video. - _changeVideo(VideoPlayerController newController) async { + _changeVideo( + VideoPlayerController newController, { + Duration? startFrom, + }) async { // Change the videoPlayerController with the new controller, // notify the controller change and remove listeners from the old controller. VideoPlayerController? oldController = videoPlayerController; @@ -139,6 +145,8 @@ class FlickVideoManager extends ChangeNotifier { videoPlayerController!.value.duration) { videoPlayerController! .seekTo(Duration(hours: 0, minutes: 0, seconds: 0, milliseconds: 0)); + } else if (startFrom != null) { + videoPlayerController?.seekTo(startFrom); } if (autoPlay && ModalRoute.of(_flickManager._context!)!.isCurrent) { @@ -181,10 +189,11 @@ class FlickVideoManager extends ChangeNotifier { // Mark video is buffering if video has not ended, has no error, // and position is equal to buffered duration. _isBuffering = !isVideoEnded && - !videoPlayerValue!.hasError && - videoPlayerController!.value.buffered.isNotEmpty == true && - videoPlayerController!.value.position.inSeconds >= - videoPlayerController!.value.buffered[0].end.inSeconds; + !videoPlayerValue!.hasError && + videoPlayerController!.value.isBuffering || + (videoPlayerController!.value.buffered.isNotEmpty == true && + videoPlayerController!.value.position.inSeconds >= + videoPlayerController!.value.buffered[0].end.inSeconds); _notify(); }