Skip to content

Conversation

@stuartmorgan-g
Copy link
Collaborator

@stuartmorgan-g stuartmorgan-g commented Jul 28, 2025

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. 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

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 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.

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.

LGTM


String? asset;
String? packageName;
String? uri;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: final?

Copy link
Collaborator Author

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.

Copy link
Contributor

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.

Copy link
Collaborator Author

@stuartmorgan-g stuartmorgan-g Jul 30, 2025

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 url variable 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_interface 6.5.0 adds a new DataSourceType.
  • video_player_avfoundation 2.9.0 adds support for the new DataSourceType, 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.)

@stuartmorgan-g stuartmorgan-g added the autosubmit Merge PR when tree becomes green via auto submit App label Jul 29, 2025
@auto-submit auto-submit bot merged commit 5d2a10f into flutter:main Jul 29, 2025
80 checks passed
@stuartmorgan-g stuartmorgan-g deleted the video-player-avfoundation-more-dart-logic branch July 30, 2025 10:06
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jul 30, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jul 30, 2025
github-merge-queue bot pushed a commit to flutter/flutter that referenced this pull request Jul 30, 2025
vashworth pushed a commit to vashworth/packages that referenced this pull request Jul 30, 2025
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.
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