Skip to content
5 changes: 5 additions & 0 deletions lib/src/helpers/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
return formattedTime;
}

/// Get the current buffering state of the video player. Will invoke a
/// Workaround for Android, as a bug in the video_player plugin prevents to get
/// the actual buffering state, always returning true and breaking ui elements.
/// For this, the actual buffer position is used to determine if the video is
/// buffering or not. See #912 for more details.
bool getIsBuffering(VideoPlayerController controller) {
final VideoPlayerValue value = controller.value;

Expand All @@ -41,16 +46,16 @@
if (value.isBuffering) {
// -> Check if we actually buffer, as android has a bug preventing to
// get the correct buffering state from this single bool.
final int position = value.position.inMilliseconds;

Check warning on line 49 in lib/src/helpers/utils.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/helpers/utils.dart#L49

Added line #L49 was not covered by tests

// Special case, if the video is finished, we don't want to show the
// buffering indicator anymore
if (position >= value.duration.inMilliseconds) {

Check warning on line 53 in lib/src/helpers/utils.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/helpers/utils.dart#L53

Added line #L53 was not covered by tests
return false;
} else {
final int buffer = value.buffered.lastOrNull?.end.inMilliseconds ?? -1;

Check warning on line 56 in lib/src/helpers/utils.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/helpers/utils.dart#L56

Added line #L56 was not covered by tests

return position >= buffer;

Check warning on line 58 in lib/src/helpers/utils.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/helpers/utils.dart#L58

Added line #L58 was not covered by tests
}
} else {
// -> No buffering
Expand All @@ -58,5 +63,5 @@
}
}

return value.isBuffering;

Check warning on line 66 in lib/src/helpers/utils.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/helpers/utils.dart#L66

Added line #L66 was not covered by tests
}