Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
0c3ff8a
Fix buffering state on Android
kmod-midori Feb 27, 2020
8174d49
Update version of video_player
kmod-midori Feb 27, 2020
5f297a5
Update CHANGELOG.md
kmod-midori Feb 27, 2020
f6e800c
Merge remote master
kmod-midori Mar 22, 2020
b11318a
Merge remote-tracking branch 'upstream/master' into fix-android-buffe…
kmod-midori May 22, 2020
0d27352
Merge tag 'video_player-v0.10.11+2' into fix-android-buffering
kmod-midori Jul 3, 2020
1697976
Merge branch 'master' into fix-android-buffering
Salakar Dec 7, 2020
c19d5e3
refactor: update changelog & pubspec version to latest version
Salakar Dec 7, 2020
ef78567
fix: android not correctly sending `bufferingEnd` event
Salakar Dec 7, 2020
b3d734b
refactor: android sending unnecessary `bufferingUpdate` event.
Salakar Dec 7, 2020
7efdab7
refactor: make `videoPlayerPlatform` visible for testing
Salakar Dec 7, 2020
ff2eb55
tests: add integration test for video buffering events
Salakar Dec 7, 2020
16abc3e
fix: implement bufferingStart/End for Web
Salakar Dec 7, 2020
a813434
chore: bump pubspec version & add changelog
Salakar Dec 7, 2020
ca34285
tests: buffering integration test should run on Android or Web only
Salakar Dec 7, 2020
78faecf
docs: changelog grammar fix
Salakar Dec 17, 2020
e4f7c6e
refactor: move `isBuffering` state to event listener
Salakar Dec 17, 2020
c58c1f7
refactor(android): define a `setBuffering` method to be used instead …
Salakar Dec 17, 2020
5240014
refactor(web): define a `setBuffering` method to be used instead of c…
Salakar Dec 17, 2020
081ce00
refactor: revert `visibleForTesting` addition and test using `network…
Salakar Dec 17, 2020
7810db5
refactor: revert removal of manual `sendBufferingUpdate` call
Salakar Dec 17, 2020
be84d1e
Merge branch 'master' into fix-android-buffering
Salakar Dec 17, 2020
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
4 changes: 4 additions & 0 deletions packages/video_player/video_player/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.0.0-nullsafety.4

* Fixed an issue where `isBuffering` was not updating on Android.

## 2.0.0-nullsafety.3

* Dart null safety requires `2.12`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,21 @@ public void onCancel(Object o) {

exoPlayer.addListener(
new EventListener() {
private boolean isBuffering = false;

public void setBuffering(boolean buffering) {
if (isBuffering != buffering) {
isBuffering = buffering;
Map<String, Object> event = new HashMap<>();
event.put("event", isBuffering ? "bufferingStart" : "bufferingEnd");
eventSink.success(event);
}
}

@Override
public void onPlaybackStateChanged(final int playbackState) {
if (playbackState == Player.STATE_BUFFERING) {
setBuffering(true);
sendBufferingUpdate();
} else if (playbackState == Player.STATE_READY) {
if (!isInitialized) {
Expand All @@ -184,10 +195,15 @@ public void onPlaybackStateChanged(final int playbackState) {
event.put("event", "completed");
eventSink.success(event);
}

if (playbackState != Player.STATE_BUFFERING) {
setBuffering(false);
}
}

@Override
public void onPlayerError(final ExoPlaybackException error) {
setBuffering(false);
if (eventSink != null) {
eventSink.error("VideoError", "Video player had error " + error, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.


// TODO(amirh): Remove this once flutter_driver supports null safety.
// https://github.com/flutter/flutter/issues/71379
// @dart = 2.9
import 'dart:async';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:integration_test/integration_test.dart';
import 'package:flutter_test/flutter_test.dart';
Expand Down Expand Up @@ -34,10 +35,58 @@ void main() {
const Duration(seconds: 7, milliseconds: 540));
});

testWidgets(
'reports buffering status',
(WidgetTester tester) async {
VideoPlayerController networkController = VideoPlayerController.network(
'https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4',
);
await networkController.initialize();
// Mute to allow playing without DOM interaction on Web.
// See https://developers.google.com/web/updates/2017/09/autoplay-policy-changes
await networkController.setVolume(0);
final Completer<void> started = Completer();
final Completer<void> ended = Completer();
bool startedBuffering = false;
bool endedBuffering = false;
networkController.addListener(() {
if (networkController.value.isBuffering && !startedBuffering) {
startedBuffering = true;
started.complete();
}
if (startedBuffering &&
!networkController.value.isBuffering &&
!endedBuffering) {
endedBuffering = true;
ended.complete();
}
});

await networkController.play();
await networkController.seekTo(const Duration(seconds: 5));
await tester.pumpAndSettle(_playDuration);
await networkController.pause();

expect(networkController.value.isPlaying, false);
expect(networkController.value.position,
(Duration position) => position > const Duration(seconds: 0));

await started;
expect(startedBuffering, true);

await ended;
expect(endedBuffering, true);
},
skip: !(kIsWeb || defaultTargetPlatform == TargetPlatform.android),
);

testWidgets(
'can be played',
(WidgetTester tester) async {
await _controller.initialize();
// Mute to allow playing without DOM interaction on Web.
// See https://developers.google.com/web/updates/2017/09/autoplay-policy-changes
await _controller.setVolume(0);

await _controller.play();
await tester.pumpAndSettle(_playDuration);
Expand All @@ -63,6 +112,9 @@ void main() {
'can be paused',
(WidgetTester tester) async {
await _controller.initialize();
// Mute to allow playing without DOM interaction on Web.
// See https://developers.google.com/web/updates/2017/09/autoplay-policy-changes
await _controller.setVolume(0);

// Play for a second, then pause, and then wait a second.
await _controller.play();
Expand Down Expand Up @@ -109,6 +161,6 @@ void main() {

await tester.pumpAndSettle();
expect(_controller.value.isPlaying, true);
});
}, skip: kIsWeb); // Web does not support local assets.
});
}
2 changes: 1 addition & 1 deletion packages/video_player/video_player/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: Flutter plugin for displaying inline video with other Flutter
# 0.10.y+z is compatible with 1.0.0, if you land a breaking change bump
# the version to 2.0.0.
# See more details: https://github.com/flutter/flutter/wiki/Package-migration-to-1.0.0
version: 2.0.0-nullsafety.3
version: 2.0.0-nullsafety.4
homepage: https://github.com/flutter/plugins/tree/master/packages/video_player/video_player

flutter:
Expand Down
4 changes: 4 additions & 0 deletions packages/video_player/video_player_web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.0.0-nullsafety.2

* Fixed an issue where `isBuffering` was not updating on Web.

## 2.0.0-nullsafety.1

* Bump Dart SDK to support null safety.
Expand Down
27 changes: 27 additions & 0 deletions packages/video_player/video_player_web/lib/video_player_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,17 @@ class _VideoPlayer {
final int textureId;
late VideoElement videoElement;
bool isInitialized = false;
bool isBuffering = false;

void setBuffering(bool buffering) {
if (isBuffering != buffering) {
isBuffering = buffering;
eventController.add(VideoEvent(
eventType: isBuffering
? VideoEventType.bufferingStart
: VideoEventType.bufferingEnd));
}
}

void initialize() {
videoElement = VideoElement()
Expand All @@ -176,10 +187,25 @@ class _VideoPlayer {
isInitialized = true;
sendInitialized();
}
setBuffering(false);
});

videoElement.onCanPlayThrough.listen((dynamic _) {
setBuffering(false);
});

videoElement.onPlaying.listen((dynamic _) {
setBuffering(false);
});

videoElement.onWaiting.listen((dynamic _) {
setBuffering(true);
sendBufferingUpdate();
});

// The error event fires when some form of error occurs while attempting to load or perform the media.
videoElement.onError.listen((Event _) {
setBuffering(false);
// The Event itself (_) doesn't contain info about the actual error.
// We need to look at the HTMLMediaElement.error.
// See: https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/error
Expand All @@ -192,6 +218,7 @@ class _VideoPlayer {
});

videoElement.onEnded.listen((dynamic _) {
setBuffering(false);
eventController.add(VideoEvent(eventType: VideoEventType.completed));
});
}
Expand Down
2 changes: 1 addition & 1 deletion packages/video_player/video_player_web/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ homepage: https://github.com/flutter/plugins/tree/master/packages/video_player/v
# 0.1.y+z is compatible with 1.0.0, if you land a breaking change bump
# the version to 2.0.0.
# See more details: https://github.com/flutter/flutter/wiki/Package-migration-to-1.0.0
version: 2.0.0-nullsafety.1
version: 2.0.0-nullsafety.2

flutter:
plugin:
Expand Down