From d0f63ee689b640793c4d4a83f95a2dd10feecaa8 Mon Sep 17 00:00:00 2001 From: "h.carnot" Date: Fri, 1 Apr 2022 13:25:12 +0200 Subject: [PATCH 1/4] feat: limit seekTo calls --- .../plugins/videoplayer/VideoPlayer.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/packages/video_player/video_player_android/android/src/main/java/io/flutter/plugins/videoplayer/VideoPlayer.java b/packages/video_player/video_player_android/android/src/main/java/io/flutter/plugins/videoplayer/VideoPlayer.java index dc7c88144583..c2e5a1d3c7e7 100644 --- a/packages/video_player/video_player_android/android/src/main/java/io/flutter/plugins/videoplayer/VideoPlayer.java +++ b/packages/video_player/video_player_android/android/src/main/java/io/flutter/plugins/videoplayer/VideoPlayer.java @@ -152,7 +152,8 @@ private MediaSource buildMediaSource( } } } - + + boolean readyToSeek = false; private void setupVideoPlayer( EventChannel eventChannel, TextureRegistry.SurfaceTextureEntry textureEntry) { eventChannel.setStreamHandler( @@ -191,6 +192,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(futureLoation != -1){ + seekTo(futureLoation); + } if (!isInitialized) { isInitialized = true; sendInitialized(); @@ -255,8 +260,19 @@ void setPlaybackSpeed(double value) { exoPlayer.setPlaybackParameters(playbackParameters); } + int futureLoation = -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; + futureLoation = -1; + exoPlayer.seekTo(location); + } + else{ + futureLoation = location; + } } long getPosition() { From 9b0b11cf1a203f21d725f643cfddf7553f401c5e Mon Sep 17 00:00:00 2001 From: "h.carnot" Date: Fri, 1 Apr 2022 13:42:55 +0200 Subject: [PATCH 2/4] fix: added changelog and version bump --- packages/video_player/video_player_android/CHANGELOG.md | 4 ++++ packages/video_player/video_player_android/pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/video_player/video_player_android/CHANGELOG.md b/packages/video_player/video_player_android/CHANGELOG.md index 1f0f06f739b2..6bd5be386339 100644 --- a/packages/video_player/video_player_android/CHANGELOG.md +++ b/packages/video_player/video_player_android/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.3.3 + +* Rate limited `seekTo` calls for ExoPlayer. + ## 2.3.2 * Updates ExoPlayer to 2.17.0. diff --git a/packages/video_player/video_player_android/pubspec.yaml b/packages/video_player/video_player_android/pubspec.yaml index aa288ed71eac..bc69fd41369a 100644 --- a/packages/video_player/video_player_android/pubspec.yaml +++ b/packages/video_player/video_player_android/pubspec.yaml @@ -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" From 38084cbd8beeb9112f834f11c73be467afca4f47 Mon Sep 17 00:00:00 2001 From: "h.carnot" Date: Fri, 1 Apr 2022 13:56:24 +0200 Subject: [PATCH 3/4] fix: format --- .../io/flutter/plugins/videoplayer/VideoPlayer.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/video_player/video_player_android/android/src/main/java/io/flutter/plugins/videoplayer/VideoPlayer.java b/packages/video_player/video_player_android/android/src/main/java/io/flutter/plugins/videoplayer/VideoPlayer.java index c2e5a1d3c7e7..5a95d16e1557 100644 --- a/packages/video_player/video_player_android/android/src/main/java/io/flutter/plugins/videoplayer/VideoPlayer.java +++ b/packages/video_player/video_player_android/android/src/main/java/io/flutter/plugins/videoplayer/VideoPlayer.java @@ -152,8 +152,9 @@ private MediaSource buildMediaSource( } } } - + boolean readyToSeek = false; + private void setupVideoPlayer( EventChannel eventChannel, TextureRegistry.SurfaceTextureEntry textureEntry) { eventChannel.setStreamHandler( @@ -193,7 +194,7 @@ public void onPlaybackStateChanged(final int playbackState) { sendBufferingUpdate(); } else if (playbackState == Player.STATE_READY) { readyToSeek = true; // indicate that seeking the video is now possible - if(futureLoation != -1){ + if (futureLoation != -1) { seekTo(futureLoation); } if (!isInitialized) { @@ -261,16 +262,16 @@ void setPlaybackSpeed(double value) { } int futureLoation = -1; + void seekTo(int 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) { + if (readyToSeek) { readyToSeek = false; futureLoation = -1; exoPlayer.seekTo(location); - } - else{ + } else { futureLoation = location; } } From 116d23218727c4cb3ba18b66147ad8822e1dd544 Mon Sep 17 00:00:00 2001 From: "h.carnot" Date: Wed, 6 Apr 2022 11:44:12 +0200 Subject: [PATCH 4/4] fix: typo --- .../io/flutter/plugins/videoplayer/VideoPlayer.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/video_player/video_player_android/android/src/main/java/io/flutter/plugins/videoplayer/VideoPlayer.java b/packages/video_player/video_player_android/android/src/main/java/io/flutter/plugins/videoplayer/VideoPlayer.java index 5a95d16e1557..a0dbb105ab44 100644 --- a/packages/video_player/video_player_android/android/src/main/java/io/flutter/plugins/videoplayer/VideoPlayer.java +++ b/packages/video_player/video_player_android/android/src/main/java/io/flutter/plugins/videoplayer/VideoPlayer.java @@ -194,8 +194,8 @@ public void onPlaybackStateChanged(final int playbackState) { sendBufferingUpdate(); } else if (playbackState == Player.STATE_READY) { readyToSeek = true; // indicate that seeking the video is now possible - if (futureLoation != -1) { - seekTo(futureLoation); + if (futureLocation != -1) { + seekTo(futureLocation); } if (!isInitialized) { isInitialized = true; @@ -261,7 +261,7 @@ void setPlaybackSpeed(double value) { exoPlayer.setPlaybackParameters(playbackParameters); } - int futureLoation = -1; + int futureLocation = -1; void seekTo(int location) { // Try to set the location, if the player is currently buffering because @@ -269,10 +269,10 @@ void seekTo(int location) { // player will be readyToSeek if (readyToSeek) { readyToSeek = false; - futureLoation = -1; + futureLocation = -1; exoPlayer.seekTo(location); } else { - futureLoation = location; + futureLocation = location; } }