getIsBuffering method
Gets the current buffering state of the video player.
For Android, it will use a workaround due to a bug
affecting the video_player plugin, preventing it from getting the
actual buffering state. This currently results in the VideoPlayerController always buffering,
thus breaking UI elements.
For this, the actual buffer position is used to determine if the video is buffering or not. See Issue #912 for more details.
Implementation
bool getIsBuffering() {
final VideoPlayerValue value = this.value;
if (defaultTargetPlatform == TargetPlatform.android) {
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;
// Special case, if the video is finished, we don't want to show the
// buffering indicator anymore
if (position >= value.duration.inMilliseconds) {
return false;
} else {
// Get the last buffered range, or -1 if none exists
final int buffer =
value.buffered.isNotEmpty
? value.buffered.last.end.inMilliseconds
: -1;
return position >= buffer;
}
} else {
// -> No buffering
return false;
}
}
return value.isBuffering;
}