Skip to content
Open
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
3 changes: 2 additions & 1 deletion packages/video_player/video_player/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## NEXT
## 2.12.0

* Passes `backBufferDurationMs` from `VideoPlayerOptions` to the underlying platform interface.
* Updates minimum supported SDK version to Flutter 3.38/Dart 3.10.

## 2.11.1
Expand Down
1 change: 1 addition & 0 deletions packages/video_player/video_player/lib/video_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
final creationOptions = platform_interface.VideoCreationOptions(
dataSource: dataSourceDescription,
viewType: viewType,
videoPlayerOptions: videoPlayerOptions,
);

if (videoPlayerOptions?.mixWithOthers != null) {
Expand Down
6 changes: 3 additions & 3 deletions packages/video_player/video_player/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Flutter plugin for displaying inline video with other Flutter
widgets on Android, iOS, macOS and web.
repository: https://github.com/flutter/packages/tree/main/packages/video_player/video_player
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22
version: 2.11.1
version: 2.12.0

environment:
sdk: ^3.10.0
Expand All @@ -26,9 +26,9 @@ dependencies:
flutter:
sdk: flutter
html: ^0.15.0
video_player_android: ^2.9.1
video_player_android: ^2.10.0
video_player_avfoundation: ^2.9.0
video_player_platform_interface: ^6.6.0
video_player_platform_interface: ^6.8.0
video_player_web: ^2.1.0

dev_dependencies:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,22 @@ void main() {
reason: 'view type must be passed to the platform',
);
});

test('back buffer duration is forwarded to platform', () async {
const expectedBackBufferDurationMs = 20000;

final controller = VideoPlayerController.networkUrl(
Uri.parse('https://127.0.0.1'),
videoPlayerOptions: VideoPlayerOptions(backBufferDurationMs: expectedBackBufferDurationMs),
);

await controller.initialize();

expect(
fakeVideoPlayerPlatform.videoPlayerOptions.last?.backBufferDurationMs,
expectedBackBufferDurationMs,
reason:
'backBufferDurationMs must be forwarded to the platform via VideoCreationOptions.videoPlayerOptions',
);
});
}
14 changes: 7 additions & 7 deletions packages/video_player/video_player/test/video_player_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1027,13 +1027,11 @@ void main() {
}

expect(isSorted, false, reason: 'Expected captions to be unsorted');
expect(captions.map((Caption c) => c.text).toList(), <String>[
'one',
'two',
'three',
'five',
'four',
], reason: 'Captions should be in original unsorted order');
expect(
captions.map((Caption c) => c.text).toList(),
<String>['one', 'two', 'three', 'five', 'four'],
reason: 'Captions should be in original unsorted order',
);
});

test('works when seeking, includes all captions', () async {
Expand Down Expand Up @@ -1900,6 +1898,7 @@ class FakeVideoPlayerPlatform extends VideoPlayerPlatform {
List<DataSource> dataSources = <DataSource>[];
List<VideoViewType> viewTypes = <VideoViewType>[];
final Map<int, StreamController<VideoEvent>> streams = <int, StreamController<VideoEvent>>{};
List<VideoPlayerOptions?> videoPlayerOptions = <VideoPlayerOptions?>[];
bool forceInitError = false;
int nextPlayerId = 0;
final Map<int, Duration> _positions = <int, Duration>{};
Expand Down Expand Up @@ -1943,6 +1942,7 @@ class FakeVideoPlayerPlatform extends VideoPlayerPlatform {
}
dataSources.add(options.dataSource);
viewTypes.add(options.viewType);
videoPlayerOptions.add(options.videoPlayerOptions);
return nextPlayerId++;
}

Expand Down
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.10.0

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

## 2.9.6

* Migrates to Built-in Kotlin to support AGP 9.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,17 @@

public class VideoPlayerOptions {
public boolean mixWithOthers;

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why a long? Seems like it's an int everywhere else.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to handle the conversion from dart to java.

We keep as a Long in VideoPlayerOptions.java to maintain alignment with Pigeon's generated CreationOptions object.

We then safely clamp the Long into a int at PlatformViewVideoPlayer.java and TextureVideoPlayer.java to match DefaultLoadControl's expected int parameter.


public VideoPlayerOptions() {}

/** Copy constructor to ensure all options are reliably copied. */
public VideoPlayerOptions(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);
}
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);
}
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