Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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.11.0

* Adds `backBufferDurationMs` to `CreationOptions` to configure ExoPlayer `DefaultLoadControl` back buffer duration.

## 2.10.0

* Implements `getVideoTracks()` and `selectVideoTrack()` methods for video track (quality) selection using ExoPlayer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@

package io.flutter.plugins.videoplayer;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

public class VideoPlayerOptions {
public boolean mixWithOthers;

/**
* The duration of the back buffer in milliseconds, used to configure ExoPlayer's load control.
*/
@Nullable public Long backBufferDurationMs;

public VideoPlayerOptions() {}

/** Copy constructor to ensure all options are reliably copied. */
public VideoPlayerOptions(@NonNull VideoPlayerOptions other) {
this.mixWithOthers = other.mixWithOthers;
this.backBufferDurationMs = other.backBufferDurationMs;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,15 @@ public long createForPlatformView(@NonNull CreationOptions options) {

long id = nextPlayerIdentifier++;
final String streamInstance = Long.toString(id);
VideoPlayerOptions playerOptions = new VideoPlayerOptions(sharedOptions);
playerOptions.backBufferDurationMs = options.getBackBufferDurationMs();

VideoPlayer videoPlayer =
PlatformViewVideoPlayer.create(
flutterState.applicationContext,
VideoPlayerEventCallbacks.bindTo(flutterState.binaryMessenger, streamInstance),
videoAsset,
sharedOptions);
playerOptions);

registerPlayerInstance(videoPlayer, id);
return id;
Expand All @@ -106,13 +109,16 @@ public long createForPlatformView(@NonNull CreationOptions options) {
long id = nextPlayerIdentifier++;
final String streamInstance = Long.toString(id);
TextureRegistry.SurfaceProducer handle = flutterState.textureRegistry.createSurfaceProducer();
VideoPlayerOptions playerOptions = new VideoPlayerOptions(sharedOptions);
playerOptions.backBufferDurationMs = options.getBackBufferDurationMs();

VideoPlayer videoPlayer =
TextureVideoPlayer.create(
flutterState.applicationContext,
VideoPlayerEventCallbacks.bindTo(flutterState.binaryMessenger, streamInstance),
handle,
videoAsset,
sharedOptions);
playerOptions);

registerPlayerInstance(videoPlayer, id);
return new TexturePlayerIds(id, handle.id());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import androidx.annotation.VisibleForTesting;
import androidx.media3.common.MediaItem;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.exoplayer.DefaultLoadControl;
import androidx.media3.exoplayer.ExoPlayer;
import io.flutter.plugins.videoplayer.ExoPlayerEventListener;
import io.flutter.plugins.videoplayer.VideoAsset;
Expand Down Expand Up @@ -56,12 +57,23 @@ public static PlatformViewVideoPlayer create(
asset.getMediaItem(),
options,
() -> {
ExoPlayer.Builder builder = new ExoPlayer.Builder(context);
if (options.backBufferDurationMs != null && options.backBufferDurationMs > 0) {
// Clamp the value to ensure it fits within the int range expected by
// DefaultLoadControl.
int backBufferInt =
(int) Math.min(options.backBufferDurationMs.longValue(), Integer.MAX_VALUE);
DefaultLoadControl loadControl =
new DefaultLoadControl.Builder()
.setBackBuffer(backBufferInt, /* retainBackBufferFromKeyframe= */ true)
.build();
builder.setLoadControl(loadControl);
}
Comment thread
sailendrabathi marked this conversation as resolved.
Resolved
androidx.media3.exoplayer.trackselection.DefaultTrackSelector trackSelector =
new androidx.media3.exoplayer.trackselection.DefaultTrackSelector(context);
ExoPlayer.Builder builder =
new ExoPlayer.Builder(context)
.setTrackSelector(trackSelector)
.setMediaSourceFactory(asset.getMediaSourceFactory(context));
builder
.setTrackSelector(trackSelector)
.setMediaSourceFactory(asset.getMediaSourceFactory(context));
return builder.build();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import androidx.annotation.VisibleForTesting;
import androidx.media3.common.MediaItem;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.exoplayer.DefaultLoadControl;
import androidx.media3.exoplayer.ExoPlayer;
import io.flutter.plugins.videoplayer.ExoPlayerEventListener;
import io.flutter.plugins.videoplayer.VideoAsset;
Expand Down Expand Up @@ -56,12 +57,23 @@ public static TextureVideoPlayer create(
asset.getMediaItem(),
options,
() -> {
ExoPlayer.Builder builder = new ExoPlayer.Builder(context);
if (options.backBufferDurationMs != null && options.backBufferDurationMs > 0) {
// Clamp the value to ensure it fits within the int range expected by
// DefaultLoadControl.
int backBufferInt =
(int) Math.min(options.backBufferDurationMs.longValue(), Integer.MAX_VALUE);
DefaultLoadControl loadControl =
new DefaultLoadControl.Builder()
.setBackBuffer(backBufferInt, /* retainBackBufferFromKeyframe= */ true)
.build();
builder.setLoadControl(loadControl);
}
Comment thread
sailendrabathi marked this conversation as resolved.
Resolved
androidx.media3.exoplayer.trackselection.DefaultTrackSelector trackSelector =
new androidx.media3.exoplayer.trackselection.DefaultTrackSelector(context);
ExoPlayer.Builder builder =
new ExoPlayer.Builder(context)
.setTrackSelector(trackSelector)
.setMediaSourceFactory(asset.getMediaSourceFactory(context));
builder
.setTrackSelector(trackSelector)
.setMediaSourceFactory(asset.getMediaSourceFactory(context));
return builder.build();
});
}
Expand Down
Loading