Skip to content

Conversation

@stuartmorgan-g
Copy link
Collaborator

Rather than having a single API to talk directly to the plugin, and having most of the methods in that API just do a map lookup and dispatch to a player instance, which was necessary when Pigeon didn't support instantiating multiple instances of an API, have each player instance set up an API instance that the Dart code can talk to directly. This follows the pattern used by plugins that migrated to Pigeon more recently (e.g., google_maps_flutter has a very similar pattern), reduces boilerplate native code, and moves closer to what an FFI-based implementation would look like if we go that route in the future.

Since the Dart unit tests needed to be significantly reworked anyway, this also moves to the pattern we are using in newer plugin code, where we use mockito to mock the Pigeon API surface. The "call log" approach it replaces dates back to pre-Pigeon, when only way to test that the right platform calls were made was to intercept and track method channel calls at the framework level.

Also updates to the latest version of Pigeon.

Pre-Review Checklist

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. 2 3

public @NonNull Long getPosition() {
long position = exoPlayer.getCurrentPosition();
// TODO(stuartmorgan): Move this; this is relying on the fact that getPosition is called
// frequently to drive buffering updates, which is a fragile hack.
Copy link
Collaborator Author

@stuartmorgan-g stuartmorgan-g Jun 27, 2025

Choose a reason for hiding this comment

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

This hack is pre-existing; it's just being moved from the VideoPlayerPlugin.java version of this method. I added the comment so that future people don't have to go through the same process I did of wondering why getting the position sends a buffer update as a side effect.

TestWidgetsFlutterBinding.ensureInitialized();

(AndroidVideoPlayer, MockAndroidVideoPlayerApi, MockVideoPlayerInstanceApi)
setUpMockPlayer({required int playerId}) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This, and the corresponding removal of the variables and setUp below, is me taking the opportunity to move away from stateful test fixtures (for the reasons described in https://abseil.io/tips/122) while I was reworking this anyway.

I could have made these state variables and configured them in setUp, following the old structure, but I'm trying to move the packages tests away from stateful fixtures over time.

when(api.create(any)).thenAnswer((_) async => newPlayerId);

const String asset = 'someAsset';
const String package = 'somePackage';
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Another opportunistic change throughout the tests; I moved from repeated-magic-values to constants. The repeated magic values is something Reid had flagged a while ago as bad patter in flutter/packages tests, so we've been slowly moving toward using a constant when we are trying to assert that values are the same across steps of a test.

@stuartmorgan-g stuartmorgan-g added the triage-android Should be looked at in Android triage label Jun 30, 2025
@stuartmorgan-g stuartmorgan-g changed the title [video_player] Move to per-player-instance Pigeon APIs [video_player] Move Android to per-player-instance Pigeon APIs Jun 30, 2025
@stuartmorgan-g
Copy link
Collaborator Author

(c.f. #9529, which is the same structural change for the Android implementation.)

@gmackall
Copy link
Member

From android triage: @ash2moon are you able to take a look at this, when you get a chance?

@stuartmorgan-g
Copy link
Collaborator Author

FYI I'm going to use this PR as a quick initial test of the new Gemini review bot we just turned on for this repo as an experiment, so you'll see some comment traffic from that.

@stuartmorgan-g
Copy link
Collaborator Author

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The code changes introduce the ability to load multiple signed images to a registry using a bulk load feature. There are a couple of potential issues related to long to int casting that could lead to bugs with very long videos or when using platform views. There is also a minor suggestion to improve a test assertion.

// Set up the instance-specific API handler, and make sure it is removed when the player is
// disposed.
BinaryMessenger messenger = flutterState.binaryMessenger;
final String channelSuffix = Integer.toString((int) id);

Choose a reason for hiding this comment

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

critical

The player id is a long. For platform view players, this ID starts near Long.MAX_VALUE. Casting it to an int with (int) id will cause an overflow, resulting in an incorrect channel suffix. This will break the communication channel for that player instance.

You should use Long.toString(id) to safely convert the long ID to a string for the channel suffix.

Suggested change
final String channelSuffix = Integer.toString((int) id);
final String channelSuffix = Long.toString(id);

Comment on lines 119 to 121
public void seekTo(@NonNull Long position) {
exoPlayer.seekTo(position.intValue());
}

Choose a reason for hiding this comment

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

high

The ExoPlayer.seekTo method expects a long value for the position in milliseconds. By casting position to an int using position.intValue(), you risk truncating the value if it exceeds Integer.MAX_VALUE (approximately 24.8 days). This can lead to incorrect seeking for very long videos.

You should pass the long value directly to seekTo.

Suggested change
public void seekTo(@NonNull Long position) {
exoPlayer.seekTo(position.intValue());
}
@Override
public void seekTo(@NonNull Long position) {
exoPlayer.seekTo(position);
}


when(mockExoPlayer.getCurrentPosition()).thenReturn(20L);
assertEquals(20L, videoPlayer.getPosition());
assertEquals(20L, videoPlayer.getPosition().doubleValue(), 0.001);

Choose a reason for hiding this comment

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

medium

The getPosition() method now returns a Long. Comparing it as a double with a delta is less precise and can hide potential issues. It's better to compare the Long values directly for equality.

Suggested change
assertEquals(20L, videoPlayer.getPosition().doubleValue(), 0.001);
assertEquals(Long.valueOf(20L), videoPlayer.getPosition());

Copy link
Contributor

@ash2moon ash2moon left a comment

Choose a reason for hiding this comment

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

LGTM!

@stuartmorgan-g stuartmorgan-g added the autosubmit Merge PR when tree becomes green via auto submit App label Jul 25, 2025
@auto-submit auto-submit bot merged commit f2ff383 into flutter:main Jul 25, 2025
78 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jul 25, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jul 25, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jul 25, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jul 28, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jul 28, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jul 28, 2025
github-merge-queue bot pushed a commit to flutter/flutter that referenced this pull request Jul 28, 2025
flutter/packages@963550c...6b2e34e

2025-07-28 [email protected]
[interactive_media_ads] Adds support to set general SDK settings
(flutter/packages#9648)
2025-07-28 [email protected] Roll Flutter from
20788c0 to cfbaa18 (43 revisions) (flutter/packages#9688)
2025-07-25 [email protected] Roll Flutter (stable) from
d7b523b to edada7c (7 revisions) (flutter/packages#9677)
2025-07-25 [email protected] Resolve `android_build_all_packages`
Warnings (flutter/packages#9643)
2025-07-25 [email protected] [video_player] Move Android to
per-player-instance Pigeon APIs (flutter/packages#9511)
2025-07-24 [email protected] [ci] Re-enable wasm and Windows ARM64
tests (flutter/packages#9667)
2025-07-24 [email protected] Roll Flutter from
afba7d7 to 20788c0 (27 revisions) (flutter/packages#9670)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC [email protected] on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
vashworth pushed a commit to vashworth/packages that referenced this pull request Jul 30, 2025
…er#9511)

Rather than having a single API to talk directly to the plugin, and having most of the methods in that API just do a map lookup and dispatch to a player instance, which was necessary when Pigeon didn't support instantiating multiple instances of an API, have each player instance set up an API instance that the Dart code can talk to directly. This follows the pattern used by plugins that migrated to Pigeon more recently (e.g., `google_maps_flutter` has a very similar pattern), reduces boilerplate native code, and moves closer to what an FFI-based implementation would look like if we go that route in the future.

Since the Dart unit tests needed to be significantly reworked anyway, this also moves to the pattern we are using in newer plugin code, where we use `mockito` to mock the Pigeon API surface. The "call log" approach it replaces dates back to pre-Pigeon, when only way to test that the right platform calls were made was to intercept and track method channel calls at the framework level.

Also updates to the latest version of Pigeon.

## Pre-Review Checklist

[^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
ksokolovskyi pushed a commit to ksokolovskyi/flutter that referenced this pull request Aug 19, 2025
flutter/packages@963550c...6b2e34e

2025-07-28 [email protected]
[interactive_media_ads] Adds support to set general SDK settings
(flutter/packages#9648)
2025-07-28 [email protected] Roll Flutter from
20788c0 to cfbaa18 (43 revisions) (flutter/packages#9688)
2025-07-25 [email protected] Roll Flutter (stable) from
d7b523b to edada7c (7 revisions) (flutter/packages#9677)
2025-07-25 [email protected] Resolve `android_build_all_packages`
Warnings (flutter/packages#9643)
2025-07-25 [email protected] [video_player] Move Android to
per-player-instance Pigeon APIs (flutter/packages#9511)
2025-07-24 [email protected] [ci] Re-enable wasm and Windows ARM64
tests (flutter/packages#9667)
2025-07-24 [email protected] Roll Flutter from
afba7d7 to 20788c0 (27 revisions) (flutter/packages#9670)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC [email protected] on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
mboetger pushed a commit to mboetger/flutter that referenced this pull request Sep 18, 2025
flutter/packages@963550c...6b2e34e

2025-07-28 [email protected]
[interactive_media_ads] Adds support to set general SDK settings
(flutter/packages#9648)
2025-07-28 [email protected] Roll Flutter from
20788c0 to cfbaa18 (43 revisions) (flutter/packages#9688)
2025-07-25 [email protected] Roll Flutter (stable) from
d7b523b to edada7c (7 revisions) (flutter/packages#9677)
2025-07-25 [email protected] Resolve `android_build_all_packages`
Warnings (flutter/packages#9643)
2025-07-25 [email protected] [video_player] Move Android to
per-player-instance Pigeon APIs (flutter/packages#9511)
2025-07-24 [email protected] [ci] Re-enable wasm and Windows ARM64
tests (flutter/packages#9667)
2025-07-24 [email protected] Roll Flutter from
afba7d7 to 20788c0 (27 revisions) (flutter/packages#9670)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC [email protected] on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
korca0220 pushed a commit to korca0220/flutter that referenced this pull request Sep 22, 2025
flutter/packages@963550c...6b2e34e

2025-07-28 [email protected]
[interactive_media_ads] Adds support to set general SDK settings
(flutter/packages#9648)
2025-07-28 [email protected] Roll Flutter from
20788c0 to cfbaa18 (43 revisions) (flutter/packages#9688)
2025-07-25 [email protected] Roll Flutter (stable) from
d7b523b to edada7c (7 revisions) (flutter/packages#9677)
2025-07-25 [email protected] Resolve `android_build_all_packages`
Warnings (flutter/packages#9643)
2025-07-25 [email protected] [video_player] Move Android to
per-player-instance Pigeon APIs (flutter/packages#9511)
2025-07-24 [email protected] [ci] Re-enable wasm and Windows ARM64
tests (flutter/packages#9667)
2025-07-24 [email protected] Roll Flutter from
afba7d7 to 20788c0 (27 revisions) (flutter/packages#9670)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC [email protected] on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
lucaantonelli pushed a commit to lucaantonelli/flutter that referenced this pull request Nov 21, 2025
flutter/packages@963550c...6b2e34e

2025-07-28 [email protected]
[interactive_media_ads] Adds support to set general SDK settings
(flutter/packages#9648)
2025-07-28 [email protected] Roll Flutter from
20788c0 to cfbaa18 (43 revisions) (flutter/packages#9688)
2025-07-25 [email protected] Roll Flutter (stable) from
d7b523b to edada7c (7 revisions) (flutter/packages#9677)
2025-07-25 [email protected] Resolve `android_build_all_packages`
Warnings (flutter/packages#9643)
2025-07-25 [email protected] [video_player] Move Android to
per-player-instance Pigeon APIs (flutter/packages#9511)
2025-07-24 [email protected] [ci] Re-enable wasm and Windows ARM64
tests (flutter/packages#9667)
2025-07-24 [email protected] Roll Flutter from
afba7d7 to 20788c0 (27 revisions) (flutter/packages#9670)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC [email protected] on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App p: video_player platform-android triage-android Should be looked at in Android triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants