Skip to content

[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

Conversation

stuartmorgan-g
Copy link
Contributor

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

@@ -186,55 +165,64 @@ - (void)initialize:(FlutterError *__autoreleasing *)error {
upgradeAudioSessionCategory(AVAudioSessionCategoryPlayback, 0, 0);
#endif

[self.playersByIdentifier.allValues makeObjectsPerformSelector:@selector(dispose)];
FlutterError *disposeError;
Copy link
Contributor

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?

Copy link
Contributor Author

@stuartmorgan-g stuartmorgan-g Aug 14, 2025

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.

Copy link
Contributor

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 {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@stuartmorgan-g stuartmorgan-g added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 15, 2025
@auto-submit auto-submit bot merged commit 201ec5a into flutter:main Aug 15, 2025
80 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 15, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 15, 2025
github-merge-queue bot pushed a commit to flutter/flutter that referenced this pull request Aug 15, 2025
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
ksokolovskyi pushed a commit to ksokolovskyi/flutter that referenced this pull request Aug 19, 2025
…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
WillBLogical pushed a commit to WillBLogical/packages that referenced this pull request Aug 20, 2025
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.
SydneyBao pushed a commit to SydneyBao/flutter that referenced this pull request Aug 22, 2025
…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
SydneyBao pushed a commit to SydneyBao/flutter that referenced this pull request Aug 22, 2025
…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
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