-
Notifications
You must be signed in to change notification settings - Fork 3.4k
[video_player] Simplify native iOS code #9800
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] Simplify native iOS code #9800
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 introduces a significant and well-executed refactoring of the native iOS/macOS code for the video_player_avfoundation
plugin. The changes simplify the API by separating player creation based on view type, moving disposal logic to player instances, and centralizing AVPlayerItem
creation. This improves code organization, reduces duplication, and enhances maintainability. The separation of player and texture IDs is also a welcome improvement. The accompanying test changes are thorough and correctly reflect the new API. I have a couple of minor suggestions to improve the changelog description and strengthen one of the tests.
packages/video_player/video_player_avfoundation/test/avfoundation_video_player_test.dart
Show resolved
Hide resolved
@@ -186,55 +165,64 @@ - (void)initialize:(FlutterError *__autoreleasing *)error { | |||
upgradeAudioSessionCategory(AVAudioSessionCategoryPlayback, 0, 0); | |||
#endif | |||
|
|||
[self.playersByIdentifier.allValues makeObjectsPerformSelector:@selector(dispose)]; | |||
FlutterError *disposeError; |
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 local variable seems write-only?
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.
Yeah, Pigeon generates its methods with non-null error pointers since it should always be calling them with a value, so they don't accidentally get dropped.
The alternative here is that I could make a public dispose
and make disposeWithError:
call that, and then have these call points call dispose
. I couldn't decide at the time if that was worth the extra method, so whichever you prefer.
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.
Ah thanks for the explanation. I'm onboard with keeping the local variable then.
if (textureBasedPlayer) { | ||
playerIdentifier = [self.registrar.textures registerTexture:textureBasedPlayer]; | ||
[textureBasedPlayer setTextureIdentifier:playerIdentifier]; | ||
} else { |
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.
Out of curiosity, is there a reason for generating playerIdentifier
differently for texture based and platform view based players? Looks like it's trying to use texture identifier as player identifier?
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.
Historically, there was only the texture ID, and that was used throughout the plugin as the identifier for the player instance. When the platform view variant was added recently, that broke down; we still needed an identifier for each player, but not all players had texture IDs.
The PRs that added platform view support renamed all the platform interface parameters from textureId
to playerId
since that was simple, but to minimize churn in already-large PRs they didn't disentangle the texture ID from the player ID in the platform implementation internals. This is paying off that tech debt by switching to having a single way to manage player IDs, and reporting texture IDs separately in the texture case.
flutter/packages@09533b7...5c52c55 2025-08-15 stuartmorgan@google.com [video_player] Move Android buffer updates to Dart (flutter/packages#9771) 2025-08-15 sfprhythnn@gmail.com [webview_flutter] Add support for payment requests on Android (flutter/packages#9679) 2025-08-15 jason-simmons@users.noreply.github.com [vector_graphics_compiler] Set the m4_10 (Z scale) value to 1 when constructing an AffineMatrix from an SVG matrix (flutter/packages#9813) 2025-08-15 magder@google.com [url_launcher_ios] Fix test button text to work on iOS 26 (flutter/packages#9766) 2025-08-15 stuartmorgan@google.com [video_player] Simplify native iOS code (flutter/packages#9800) 2025-08-14 stuartmorgan@google.com [image_picker] Add the ability to pick multiple videos - platform_interface (flutter/packages#9804) 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 flutter-ecosystem@google.com 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
…r#173854) flutter/packages@09533b7...5c52c55 2025-08-15 stuartmorgan@google.com [video_player] Move Android buffer updates to Dart (flutter/packages#9771) 2025-08-15 sfprhythnn@gmail.com [webview_flutter] Add support for payment requests on Android (flutter/packages#9679) 2025-08-15 jason-simmons@users.noreply.github.com [vector_graphics_compiler] Set the m4_10 (Z scale) value to 1 when constructing an AffineMatrix from an SVG matrix (flutter/packages#9813) 2025-08-15 magder@google.com [url_launcher_ios] Fix test button text to work on iOS 26 (flutter/packages#9766) 2025-08-15 stuartmorgan@google.com [video_player] Simplify native iOS code (flutter/packages#9800) 2025-08-14 stuartmorgan@google.com [image_picker] Add the ability to pick multiple videos - platform_interface (flutter/packages#9804) 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 flutter-ecosystem@google.com 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
Refactors and simplifies some of the native code in `video_player_avfoundation`: - Separates `create` into two different entry points for the two display types, instead of having one entry point and then branching several times based on the display type. - Moves `dispose` to the player instance, with the other instance-specific calls, by making plugin-level tracking cleanup part of `onDispose`. - Moves the URL->`AVPlayerItem` logic out of the two player classes and into a central helper in the plugin class, reducing duplication and simplifying the player initialization logic. - Addresses the TODO to separate texture IDs from player IDs. - Makes `expectFrame` a private implementation detail rather than making a client call it. - Removes an ARC check; we have used ARC everywhere in this repo for a long time. 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.
…r#173854) flutter/packages@09533b7...5c52c55 2025-08-15 stuartmorgan@google.com [video_player] Move Android buffer updates to Dart (flutter/packages#9771) 2025-08-15 sfprhythnn@gmail.com [webview_flutter] Add support for payment requests on Android (flutter/packages#9679) 2025-08-15 jason-simmons@users.noreply.github.com [vector_graphics_compiler] Set the m4_10 (Z scale) value to 1 when constructing an AffineMatrix from an SVG matrix (flutter/packages#9813) 2025-08-15 magder@google.com [url_launcher_ios] Fix test button text to work on iOS 26 (flutter/packages#9766) 2025-08-15 stuartmorgan@google.com [video_player] Simplify native iOS code (flutter/packages#9800) 2025-08-14 stuartmorgan@google.com [image_picker] Add the ability to pick multiple videos - platform_interface (flutter/packages#9804) 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 flutter-ecosystem@google.com 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
…r#173854) flutter/packages@09533b7...5c52c55 2025-08-15 stuartmorgan@google.com [video_player] Move Android buffer updates to Dart (flutter/packages#9771) 2025-08-15 sfprhythnn@gmail.com [webview_flutter] Add support for payment requests on Android (flutter/packages#9679) 2025-08-15 jason-simmons@users.noreply.github.com [vector_graphics_compiler] Set the m4_10 (Z scale) value to 1 when constructing an AffineMatrix from an SVG matrix (flutter/packages#9813) 2025-08-15 magder@google.com [url_launcher_ios] Fix test button text to work on iOS 26 (flutter/packages#9766) 2025-08-15 stuartmorgan@google.com [video_player] Simplify native iOS code (flutter/packages#9800) 2025-08-14 stuartmorgan@google.com [image_picker] Add the ability to pick multiple videos - platform_interface (flutter/packages#9804) 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 flutter-ecosystem@google.com 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
Refactors and simplifies some of the native code in
video_player_avfoundation
:create
into two different entry points for the two display types, instead of having one entry point and then branching several times based on the display type.dispose
to the player instance, with the other instance-specific calls, by making plugin-level tracking cleanup part ofonDispose
.AVPlayerItem
logic out of the two player classes and into a central helper in the plugin class, reducing duplication and simplifying the player initialization logic.expectFrame
a private implementation detail rather than making a client call it.Part of flutter/flutter#172763
Pre-Review Checklist
[shared_preferences]
pubspec.yaml
with 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.md
to 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-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
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