Skip to content

Add workaround for invalid buffering info on android #912

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

Merged
Merged
33 changes: 31 additions & 2 deletions lib/src/cupertino/cupertino_controls.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:async';
import 'dart:io';
import 'dart:math' as math;
import 'dart:ui' as ui;

Expand Down Expand Up @@ -810,9 +811,37 @@
void _updateState() {
if (!mounted) return;

late final bool buffering;

if (Platform.isAndroid) {
if (controller.value.isBuffering) {

Check warning on line 817 in lib/src/cupertino/cupertino_controls.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/cupertino/cupertino_controls.dart#L817

Added line #L817 was not covered by tests
// -> Check if we actually buffer, as android has a bug preventing to
// get the correct buffering state from this single bool.
final VideoPlayerValue value = controller.value;

Check warning on line 820 in lib/src/cupertino/cupertino_controls.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/cupertino/cupertino_controls.dart#L820

Added line #L820 was not covered by tests

final int position = value.position.inMilliseconds;

Check warning on line 822 in lib/src/cupertino/cupertino_controls.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/cupertino/cupertino_controls.dart#L822

Added line #L822 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 826 in lib/src/cupertino/cupertino_controls.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/cupertino/cupertino_controls.dart#L826

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

Check warning on line 830 in lib/src/cupertino/cupertino_controls.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/cupertino/cupertino_controls.dart#L830

Added line #L830 was not covered by tests

buffering = position >= buffer;

Check warning on line 832 in lib/src/cupertino/cupertino_controls.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/cupertino/cupertino_controls.dart#L832

Added line #L832 was not covered by tests
}
} else {
// -> No buffering
buffering = false;
}
} else {
buffering = controller.value.isBuffering;
}

// display the progress bar indicator only after the buffering delay if it has been set
if (chewieController.progressIndicatorDelay != null) {
if (controller.value.isBuffering) {
if (buffering) {
_bufferingDisplayTimer ??= Timer(
chewieController.progressIndicatorDelay!,
_bufferingTimerTimeout,
Expand All @@ -823,7 +852,7 @@
_displayBufferingIndicator = false;
}
} else {
_displayBufferingIndicator = controller.value.isBuffering;
_displayBufferingIndicator = buffering;
}

setState(() {
Expand Down
33 changes: 31 additions & 2 deletions lib/src/material/material_controls.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:async';
import 'dart:io';

import 'package:chewie/src/center_play_button.dart';
import 'package:chewie/src/center_seek_button.dart';
Expand Down Expand Up @@ -645,9 +646,37 @@
void _updateState() {
if (!mounted) return;

late final bool buffering;

if (Platform.isAndroid) {
if (controller.value.isBuffering) {

Check warning on line 652 in lib/src/material/material_controls.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/material/material_controls.dart#L652

Added line #L652 was not covered by tests
// -> Check if we actually buffer, as android has a bug preventing to
// get the correct buffering state from this single bool.
final VideoPlayerValue value = controller.value;

Check warning on line 655 in lib/src/material/material_controls.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/material/material_controls.dart#L655

Added line #L655 was not covered by tests

final int position = value.position.inMilliseconds;

Check warning on line 657 in lib/src/material/material_controls.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/material/material_controls.dart#L657

Added line #L657 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 661 in lib/src/material/material_controls.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/material/material_controls.dart#L661

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

Check warning on line 665 in lib/src/material/material_controls.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/material/material_controls.dart#L665

Added line #L665 was not covered by tests

buffering = position >= buffer;

Check warning on line 667 in lib/src/material/material_controls.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/material/material_controls.dart#L667

Added line #L667 was not covered by tests
}
} else {
// -> No buffering
buffering = false;
}
} else {
buffering = controller.value.isBuffering;
}

// display the progress bar indicator only after the buffering delay if it has been set
if (chewieController.progressIndicatorDelay != null) {
if (controller.value.isBuffering) {
if (buffering) {
_bufferingDisplayTimer ??= Timer(
chewieController.progressIndicatorDelay!,
_bufferingTimerTimeout,
Expand All @@ -658,7 +687,7 @@
_displayBufferingIndicator = false;
}
} else {
_displayBufferingIndicator = controller.value.isBuffering;
_displayBufferingIndicator = buffering;
}

setState(() {
Expand Down
33 changes: 31 additions & 2 deletions lib/src/material/material_desktop_controls.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:async';
import 'dart:io';

import 'package:chewie/src/animated_play_pause.dart';
import 'package:chewie/src/center_play_button.dart';
Expand Down Expand Up @@ -581,9 +582,37 @@
void _updateState() {
if (!mounted) return;

late final bool buffering;

if (Platform.isAndroid) {
if (controller.value.isBuffering) {

Check warning on line 588 in lib/src/material/material_desktop_controls.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/material/material_desktop_controls.dart#L588

Added line #L588 was not covered by tests
// -> Check if we actually buffer, as android has a bug preventing to
// get the correct buffering state from this single bool.
final VideoPlayerValue value = controller.value;

Check warning on line 591 in lib/src/material/material_desktop_controls.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/material/material_desktop_controls.dart#L591

Added line #L591 was not covered by tests

final int position = value.position.inMilliseconds;

Check warning on line 593 in lib/src/material/material_desktop_controls.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/material/material_desktop_controls.dart#L593

Added line #L593 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 597 in lib/src/material/material_desktop_controls.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/material/material_desktop_controls.dart#L597

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

Check warning on line 601 in lib/src/material/material_desktop_controls.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/material/material_desktop_controls.dart#L601

Added line #L601 was not covered by tests

buffering = position >= buffer;

Check warning on line 603 in lib/src/material/material_desktop_controls.dart

View check run for this annotation

Codecov / codecov/patch

lib/src/material/material_desktop_controls.dart#L603

Added line #L603 was not covered by tests
}
} else {
// -> No buffering
buffering = false;
}
} else {
buffering = controller.value.isBuffering;
}

// display the progress bar indicator only after the buffering delay if it has been set
if (chewieController.progressIndicatorDelay != null) {
if (controller.value.isBuffering) {
if (buffering) {
_bufferingDisplayTimer ??= Timer(
chewieController.progressIndicatorDelay!,
_bufferingTimerTimeout,
Expand All @@ -594,7 +623,7 @@
_displayBufferingIndicator = false;
}
} else {
_displayBufferingIndicator = controller.value.isBuffering;
_displayBufferingIndicator = buffering;
}

setState(() {
Expand Down