Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed loader not showing up while buffering #216

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import FlutterMacOS
import Foundation

import path_provider_macos
import path_provider_foundation
import wakelock_macos

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
Expand Down
18 changes: 12 additions & 6 deletions lib/src/manager/flick_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
29 changes: 19 additions & 10 deletions lib/src/manager/video_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
}
Expand Down