-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[video_player] Move Android to per-player-instance Pigeon APIs #9511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[video_player] Move Android to per-player-instance Pigeon APIs #9511
Conversation
| 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. |
There was a problem hiding this comment.
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}) { |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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.
|
(c.f. #9529, which is the same structural change for the Android implementation.) |
|
From android triage: @ash2moon are you able to take a look at this, when you get a chance? |
|
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. |
|
/gemini review |
There was a problem hiding this 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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| final String channelSuffix = Integer.toString((int) id); | |
| final String channelSuffix = Long.toString(id); |
| public void seekTo(@NonNull Long position) { | ||
| exoPlayer.seekTo(position.intValue()); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| 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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| assertEquals(20L, videoPlayer.getPosition().doubleValue(), 0.001); | |
| assertEquals(Long.valueOf(20L), videoPlayer.getPosition()); |
ash2moon
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
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
…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.
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
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
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
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
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_flutterhas 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
mockitoto 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
[shared_preferences]pubspec.yamlwith an appropriate new version according to the pub versioning philosophy, or I have commented below to indicate which version change exemption this PR falls under1.CHANGELOG.mdto add a description of the change, following repository CHANGELOG style, or I have commented below to indicate which CHANGELOG exemption this PR falls under1.///).Footnotes
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