-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[video_player] Move more Obj-C logic to Dart #9685
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 more Obj-C logic to Dart #9685
Conversation
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 moves asset-to-URL resolution logic from Objective-C to Dart, which improves the architecture. The native code refactoring, such as removing redundant state and simplifying player creation, is well done, and the tests are updated to cover the new logic. A missing break in a switch statement will cause asset loading to fail, and a comment with a suggested fix has been provided.
packages/video_player/video_player_avfoundation/lib/src/avfoundation_video_player.dart
Show resolved
Hide resolved
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.
LGTM
|
|
||
| String? asset; | ||
| String? packageName; | ||
| String? uri; |
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.
nit: final?
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.
That would make the code fail to compile if another type were added to DataSourceType, which is from a different package (and thus could be updated separately by clients). And preventing that would require a default case, which would mean we wouldn't get a warning about a non-exhaustive cases locally as a flag to update this code. So non-final has enough benefits to outweigh the downside.
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.
Hmm I'm not sure I understand. The switch statement below is exhaustive and for each case in the switch the url variable is assigned exactly once so it could be final I think? I thought there's lint for this not sure why it is not complaining.
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 switch statement below is exhaustive and for each case in the switch the
urlvariable is assigned exactly once so it could be final I think?
Yes, right now, with video_player_platform_interface 6.4.0, it is exhaustive.
So imagine we had made it final, and published that as video_player_avfoundation 2.8.1. Then next week, we decide to add a new source type (e.g., in-memory bytes). So we make a series of PRs for the packages to add support for it, including:
video_player_platform_interface6.5.0 adds a newDataSourceType.video_player_avfoundation2.9.0 adds support for the newDataSourceType, including updating this switch statement.
Now consider a client who updates video_player_platform_interface without updating video_player_avfoundation, which is perfectly valid. At this point the code no longer compiles.
The only way to prevent that outcome would be to make adding a new enum value be a major version change for the platform interface, and we a) try very hard to not make breaking changes to platform interface packages, and b) don't generally consider adding an enum value to be a breaking change.
So instead we code defensively in our switch statements that use cross-package enums. (I actually have a long-standing open feature request for a lint that would tell people not to rely on exhaustive switches for cross-platform enums, to use in libraries, for exactly this reason.)
flutter/packages@ed235d1...d914120 2025-07-30 [email protected] Roll Flutter from 46b097a to c3279ca (18 revisions) (flutter/packages#9699) 2025-07-29 [email protected] [video_player] Move more Obj-C logic to Dart (flutter/packages#9685) 2025-07-29 [email protected] Update CODEOWNERS (flutter/packages#9692) 2025-07-29 [email protected] [video_player] Move more Java logic to Dart (flutter/packages#9672) 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
Moves some logic from native code to Dart: - Asset -> URL lookup. - Conversion from native buffer range format (start+duration) to Dart range format (start+end). Also does some minor native cleanup: - Removes unnecessary state from `FVPVideoPlayerPlugin`; several registrar-vended objects were being stored, and later changes required storing the registrar itself, so now we can just get those from the registrar on demand. - Removes nil player handling; the player can never return nil now. - Removes `formatHint` from the Pigeon interface; it was only ever used on Android, so doesn't need to be sent across the language boundary. Part of flutter/flutter#172763 ## Pre-Review Checklist **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). 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. [^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@ed235d1...d914120 2025-07-30 [email protected] Roll Flutter from 46b097a to c3279ca (18 revisions) (flutter/packages#9699) 2025-07-29 [email protected] [video_player] Move more Obj-C logic to Dart (flutter/packages#9685) 2025-07-29 [email protected] Update CODEOWNERS (flutter/packages#9692) 2025-07-29 [email protected] [video_player] Move more Java logic to Dart (flutter/packages#9672) 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@ed235d1...d914120 2025-07-30 [email protected] Roll Flutter from 46b097a to c3279ca (18 revisions) (flutter/packages#9699) 2025-07-29 [email protected] [video_player] Move more Obj-C logic to Dart (flutter/packages#9685) 2025-07-29 [email protected] Update CODEOWNERS (flutter/packages#9692) 2025-07-29 [email protected] [video_player] Move more Java logic to Dart (flutter/packages#9672) 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@ed235d1...d914120 2025-07-30 [email protected] Roll Flutter from 46b097a to c3279ca (18 revisions) (flutter/packages#9699) 2025-07-29 [email protected] [video_player] Move more Obj-C logic to Dart (flutter/packages#9685) 2025-07-29 [email protected] Update CODEOWNERS (flutter/packages#9692) 2025-07-29 [email protected] [video_player] Move more Java logic to Dart (flutter/packages#9672) 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@ed235d1...d914120 2025-07-30 [email protected] Roll Flutter from 46b097a to c3279ca (18 revisions) (flutter/packages#9699) 2025-07-29 [email protected] [video_player] Move more Obj-C logic to Dart (flutter/packages#9685) 2025-07-29 [email protected] Update CODEOWNERS (flutter/packages#9692) 2025-07-29 [email protected] [video_player] Move more Java logic to Dart (flutter/packages#9672) 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
Moves some logic from native code to Dart:
Also does some minor native cleanup:
FVPVideoPlayerPlugin; several registrar-vended objects were being stored, and later changes required storing the registrar itself, so now we can just get those from the registrar on demand.formatHintfrom the Pigeon interface; it was only ever used on Android, so doesn't need to be sent across the language boundary.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