-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[video_player] Separate event stream from player on iOS #9700
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] Separate event stream from player on iOS #9700
Conversation
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
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
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.
...undation/darwin/video_player_avfoundation/Sources/video_player_avfoundation/FVPVideoPlayer.m
Show resolved
Hide resolved
packages/video_player/video_player_avfoundation/darwin/RunnerTests/VideoPlayerTests.m
Outdated
Show resolved
Hide resolved
...undation/darwin/video_player_avfoundation/Sources/video_player_avfoundation/FVPEventBridge.m
Outdated
Show resolved
Hide resolved
|
/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
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.
...undation/darwin/video_player_avfoundation/Sources/video_player_avfoundation/FVPEventBridge.m
Outdated
Show resolved
Hide resolved
.../Sources/video_player_avfoundation/include/video_player_avfoundation/FVPVideoEventListener.h
Outdated
Show resolved
Hide resolved
| return nil; | ||
| } | ||
|
|
||
| - (FlutterError *_Nullable)onCancelWithArguments:(id _Nullable)arguments { |
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 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?
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 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.)
LongCatIsLooong
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.
Whoops forgot to LGTM
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
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
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
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
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
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
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
[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.///).Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assistbot 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
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