Skip to content

Commit 9c11e9b

Browse files
[video_player_android] isBuffering flag always return true after calling seekTo method - fixed (#9198)
fixes [Issue #165149](flutter/flutter#165149) ## Pre-Review Checklist ### Root Cause The issue stems from the `onPlaybackStateChanged` callback. After calling `seekTo`, the player transitions to `Player.STATE_BUFFERING`, setting the buffering flag to `true`. Shortly after, it transitions to `Player.STATE_READY`. However, if the player was already initialized, the method returned early due to: ```java if (isInitialized) { return; } ``` prevented `setBuffering(false)` from being called in the shared logic below the switch
1 parent 6efa04b commit 9c11e9b

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

packages/video_player/video_player_android/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 2.8.6
2+
3+
* Fixes a [bug](https://github.com/flutter/flutter/issues/165149) where the `isBuffering` flag
4+
always returns true after seeking to any position.
5+
16
## 2.8.5
27

38
* Replaces deprecated `onSurfaceDestroyed` with `onSurfaceCleanup`.

packages/video_player/video_player_android/android/src/main/java/io/flutter/plugins/videoplayer/ExoPlayerEventListener.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,10 @@ public void onPlaybackStateChanged(final int playbackState) {
6969
events.onBufferingUpdate(exoPlayer.getBufferedPosition());
7070
break;
7171
case Player.STATE_READY:
72-
if (isInitialized) {
73-
return;
72+
if (!isInitialized) {
73+
isInitialized = true;
74+
sendInitialized();
7475
}
75-
isInitialized = true;
76-
sendInitialized();
7776
break;
7877
case Player.STATE_ENDED:
7978
events.onCompleted();

packages/video_player/video_player_android/android/src/test/java/io/flutter/plugins/videoplayer/ExoPlayerEventListenerTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,19 @@ public void onPlaybackStateChangedEndedAfterBufferingSendsBufferingEndAndOnCompl
9494
verifyNoMoreInteractions(mockCallbacks);
9595
}
9696

97+
@Test
98+
public void onPlaybackStateChangedReadyAfterBufferingSendsBufferingEnd() {
99+
when(mockExoPlayer.getBufferedPosition()).thenReturn(10L);
100+
eventListener.onPlaybackStateChanged(Player.STATE_BUFFERING);
101+
verify(mockCallbacks).onBufferingStart();
102+
verify(mockCallbacks).onBufferingUpdate(10L);
103+
104+
eventListener.onPlaybackStateChanged(Player.STATE_READY);
105+
verify(mockCallbacks).onBufferingEnd();
106+
107+
verifyNoMoreInteractions(mockCallbacks);
108+
}
109+
97110
@Test
98111
public void onPlaybackStateChangedIdleDoNothing() {
99112
eventListener.onPlaybackStateChanged(Player.STATE_IDLE);

packages/video_player/video_player_android/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: video_player_android
22
description: Android implementation of the video_player plugin.
33
repository: https://github.com/flutter/packages/tree/main/packages/video_player/video_player_android
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22
5-
version: 2.8.5
5+
version: 2.8.6
66

77
environment:
88
sdk: ^3.7.0

0 commit comments

Comments
 (0)