Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[video_player] Increase seeking performance #5145

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.3.3

* Rate limited `seekTo` calls for ExoPlayer.

## 2.3.2

* Updates ExoPlayer to 2.17.0.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ private MediaSource buildMediaSource(
}
}

boolean readyToSeek = false;

private void setupVideoPlayer(
EventChannel eventChannel, TextureRegistry.SurfaceTextureEntry textureEntry) {
eventChannel.setStreamHandler(
Expand Down Expand Up @@ -191,6 +193,10 @@ public void onPlaybackStateChanged(final int playbackState) {
setBuffering(true);
sendBufferingUpdate();
} else if (playbackState == Player.STATE_READY) {
readyToSeek = true; // indicate that seeking the video is now possible
if (futureLocation != -1) {
seekTo(futureLocation);
}
if (!isInitialized) {
isInitialized = true;
sendInitialized();
Expand Down Expand Up @@ -255,8 +261,19 @@ void setPlaybackSpeed(double value) {
exoPlayer.setPlaybackParameters(playbackParameters);
}

int futureLocation = -1;

void seekTo(int location) {
exoPlayer.seekTo(location);
// Try to set the location, if the player is currently buffering because
// of a previous seekTo, save the futureLocation to be seeked when the
// player will be readyToSeek
if (readyToSeek) {
readyToSeek = false;
futureLocation = -1;
exoPlayer.seekTo(location);
} else {
futureLocation = location;
}
}

long getPosition() {
Expand Down
2 changes: 1 addition & 1 deletion packages/video_player/video_player_android/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: video_player_android
description: Android implementation of the video_player plugin.
repository: https://github.com/flutter/plugins/tree/master/packages/video_player/video_player_android
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22
version: 2.3.2
version: 2.3.3

environment:
sdk: ">=2.14.0 <3.0.0"
Expand Down