Skip to content

Conversation

@stuartmorgan-g
Copy link
Collaborator

Abstracts the details of the native->Dart communication system from the player instance by adding a listener protocol, and moving the event channel into an implementation of that protocol.

Also simplifies the logic to avoid messaging races during channel setup by adding a generic queue to the listener implementation instead of requiring the player to track whether or not it's allowed to send messages, and hard-coding specific messages to re-send later.

Part of flutter/flutter#172763

Pre-Review Checklist

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

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

Abstracts the details of the native->Dart communication system from the
player instance by adding a listener protocol, and moving the event
channel into an implementation of that protocol.

Also simplifies the logic to avoid messaging races during channel setup
by adding a generic queue to the listener implementation instead of
requiring the player to track whether or not it's allowed to send
messages, and hard-coding specific messages to re-send later.

Part of flutter/flutter#172763
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

This pull request refactors the event handling mechanism on iOS to decouple the video player from the Flutter event channel implementation. It introduces a new FVPVideoEventListener protocol and an FVPEventBridge class that handles communication with Dart. This is a good architectural improvement that increases modularity and testability. The changes also fix a potential race condition during event channel setup by queueing events. The review identified a few issues: a high-severity bug where an event was being sent inside a loop incorrectly, and some medium-severity maintainability issues related to typos in test code and property attributes.

@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

This pull request refactors the native video player by introducing an FVPVideoEventListener protocol, decoupling it from the Flutter event channel communication. This improves the architecture and maintainability of the code. The addition of an event queue in FVPEventBridge to handle potential race conditions during initialization is also a great improvement.

The tests have been updated to reflect these changes, using a stub implementation of the new listener protocol, which makes them cleaner.

I have a couple of minor suggestions to improve code clarity and type safety.

return nil;
}

- (FlutterError *_Nullable)onCancelWithArguments:(id _Nullable)arguments {
Copy link
Contributor

Choose a reason for hiding this comment

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

The documentation says:

Such request pairs may occur during Flutter hot restart.

Are plugins destroyed and recreated during hot restart, or they live through hot restart? If it's the latter then the event queue is always nil after a hot restart?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The native code's plugin instance survives hot restart, but video_player calls an init method when the Dart plugin instance (which doesn't survive) is created, which will call this code and destroy all the player instances, and thus their bridges.

(Even if it didn't, since these channels have ID-based names, and the IDs are assigned by the native code, after a hot restart it should never be possible for the Dart code to try re-listening to any previously-existing video player event channels anyway.)

Copy link
Contributor

@LongCatIsLooong LongCatIsLooong left a comment

Choose a reason for hiding this comment

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

Whoops forgot to LGTM

@stuartmorgan-g stuartmorgan-g added the autosubmit Merge PR when tree becomes green via auto submit App label Jul 31, 2025
@auto-submit auto-submit bot merged commit fe53da2 into flutter:main Jul 31, 2025
80 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 1, 2025
github-merge-queue bot pushed a commit to flutter/flutter that referenced this pull request Aug 1, 2025
flutter/packages@db6988d...f0645d8

2025-08-01 [email protected] Mark `FlutterIOOverrides` as `final`
(flutter/packages#9719)
2025-07-31 [email protected]
[in_app_purchase_storekit] Updated comment (flutter/packages#9445)
2025-07-31 [email protected] [video_player] Separate event stream
from player on iOS (flutter/packages#9700)

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
SydneyBao pushed a commit to SydneyBao/flutter that referenced this pull request Aug 6, 2025
ksokolovskyi pushed a commit to ksokolovskyi/flutter that referenced this pull request Aug 19, 2025
mboetger pushed a commit to mboetger/flutter that referenced this pull request Sep 18, 2025
korca0220 pushed a commit to korca0220/flutter that referenced this pull request Sep 22, 2025
lucaantonelli pushed a commit to lucaantonelli/flutter that referenced this pull request Nov 21, 2025
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-ios platform-macos

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants