-
Notifications
You must be signed in to change notification settings - Fork 3.6k
feat(ios): add audio track selection support for AVFoundation #10313
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
base: main
Are you sure you want to change the base?
feat(ios): add audio track selection support for AVFoundation #10313
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 audio track selection support for AVFoundation, enabling users to retrieve and select audio tracks from both HLS streams and regular video files. The changes include modifications to the CHANGELOG, platform-specific code (ObjC, Swift), example app, and test files. The minimum supported SDK versions have been updated, and new methods (getAudioTracks(), selectAudioTrack()) have been implemented. The code adheres to the repository's style guide, focusing on objective summaries and using code as the source of truth.
packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation.podspec
Outdated
Show resolved
Hide resolved
packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Package.swift
Outdated
Show resolved
Hide resolved
| // Skip nil options | ||
| if (!option || [option isKindOfClass:[NSNull class]]) { | ||
| continue; |
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.
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.
+1, why are we checking against NSNull or checking if the option is nil?
| } | ||
| // For asset tracks, we don't have a direct way to select them in AVFoundation | ||
| // This would require more complex track selection logic that's not commonly used |
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.
packages/video_player/video_player_avfoundation/example/ios/Flutter/AppFrameworkInfo.plist
Outdated
Show resolved
Hide resolved
packages/video_player/video_player_avfoundation/example/ios/Runner.xcodeproj/project.pbxproj
Outdated
Show resolved
Hide resolved
packages/video_player/video_player_avfoundation/example/macos/Podfile
Outdated
Show resolved
Hide resolved
packages/video_player/video_player_avfoundation/example/macos/Runner.xcodeproj/project.pbxproj
Outdated
Show resolved
Hide resolved
| assets: | ||
| - assets/flutter-mark-square-64.png | ||
| - assets/Butterfly-209.mp4 | ||
| # FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE. |
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.
Per the repository style guide, the review agent should not comment about dependency_overrides sections in pubspec.yaml files that have a comment starting with: "FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE." 1
Style Guide References
Footnotes
- Added getAudioTracks() method supporting both HLS media selection and regular asset tracks - Added selectAudioTrack() method with support for both track selection mechanisms - Included comprehensive test coverage for audio track functionality with edge cases
4784bd8 to
459e7f8
Compare
- Update iOS minimum deployment target from 12.0 to 13.0 - Update macOS minimum deployment target from 10.14 to 10.15 - Add CocoaPods framework embedding build phases to Xcode projects
|
@LongCatIsLooong @tarrinneal could you please review this PR |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, I've been out as my wife is recovering from surgery. I'll try to get to this in the next couple days. |
|
(just started reviewing this, I'll finish doing the review tomorrow, sorry for the delay I was working on a bugfix). |
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.
So far I've only looked at the objective-c implementation.
My biggest question: why is it required to drop down to lower-level AVAssetTrack stuff? I went to read a little about media selection group and my understanding is that it should be sufficient for most user-facing use cases. What are the use cases for the tracks information?
Additionally, track loading is lazy and asynchronous according to the documentation. I don't see logic that handles the asynchronism.
...undation/darwin/video_player_avfoundation/Sources/video_player_avfoundation/FVPVideoPlayer.m
Outdated
Show resolved
Hide resolved
| NSMutableArray<FVPMediaSelectionAudioTrackData *> *mediaSelectionTracks = | ||
| [[NSMutableArray alloc] init]; | ||
| AVMediaSelectionOption *currentSelection = nil; | ||
| if (@available(iOS 11.0, macOS 10.13, *)) { |
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.
I thought the plugin's lowest supported iOS version is 13.0 so we don't have to resort to the deprecated API?
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.
yaa but The @available(iOS 11.0, macOS 10.13, *) syntax is already being used consistently in the codebase , lemme know if you want me to remove it.
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
@available(iOS 11.0, macOS 10.13, *)syntax is already being used consistently in the codebase
There are zero instances in this repository where we check for a min OS version less than the minimum supported OS version.
If you mean that @available in general is used in the codebase, we consistently use it when we need different codepaths for different supported OS versions.
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.
updated
| // Skip nil options | ||
| if (!option || [option isKindOfClass:[NSNull class]]) { | ||
| continue; |
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.
+1, why are we checking against NSNull or checking if the option is nil?
...undation/darwin/video_player_avfoundation/Sources/video_player_avfoundation/FVPVideoPlayer.m
Outdated
Show resolved
Hide resolved
...undation/darwin/video_player_avfoundation/Sources/video_player_avfoundation/FVPVideoPlayer.m
Outdated
Show resolved
Hide resolved
...undation/darwin/video_player_avfoundation/Sources/video_player_avfoundation/FVPVideoPlayer.m
Outdated
Show resolved
Hide resolved
...undation/darwin/video_player_avfoundation/Sources/video_player_avfoundation/FVPVideoPlayer.m
Outdated
Show resolved
Hide resolved
...undation/darwin/video_player_avfoundation/Sources/video_player_avfoundation/FVPVideoPlayer.m
Outdated
Show resolved
Hide resolved
...undation/darwin/video_player_avfoundation/Sources/video_player_avfoundation/FVPVideoPlayer.m
Show resolved
Hide resolved
...undation/darwin/video_player_avfoundation/Sources/video_player_avfoundation/FVPVideoPlayer.m
Outdated
Show resolved
Hide resolved
…layer_avfoundation/Sources/video_player_avfoundation/FVPVideoPlayer.m Co-authored-by: LongCatIsLooong <[email protected]>
- Remove _cachedAudioSelectionOptions instance variable - Fetch options from media selection group each time in selectAudioTrack - Address PR review feedback from LongCatIsLooong
- Remove unnecessary nil checks for AVMediaSelectionOption - Remove redundant equality check in isSelected comparison - Simplify commonMetadataTitle extraction - Remove try-catch block and type validation for format description parsing - Remove defensive checks for Core Media format descriptions - Streamline audio format description extraction logic
…ayer - Return FlutterError instead of empty data when video not loaded in getAudioTracks - Return FlutterError instead of silently failing in selectAudioTrack when no video loaded - Remove test for nil media selection option handling (no longer needed) - Add getAudioTracks and selectAudioTrack helper methods to _PlayerInstance - Apply dart format to fix code style inconsistencies
…/flutter_packages into 28-oct-platform-avfoundation
|
@LongCatIsLooong thanks for the detailed review. Have addressed all the comments, can you please check ? |
|
|
||
| - (nullable FVPNativeAudioTrackData *)getAudioTracks:(FlutterError *_Nullable *_Nonnull)error { | ||
| AVPlayerItem *currentItem = _player.currentItem; | ||
| if (!currentItem) { |
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.
I don't think the code here is reachable. currentItem is set in init so you can assume it's not nil (so this should probably be removed, or use a NSAssert instead)
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.
Same goes for the currentItem check in selectAudioTrackWithType
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.
updated
…methods - Replace FlutterError returns with NSAssert for nil currentItem checks in getAudioTracks and selectAudioTrack - Remove deprecated iOS 10/macOS 10.12 compatibility code for selectedMediaOptionInMediaSelectionGroup - Use currentMediaSelection API directly (available since iOS 11.0/macOS 10.13)
- Remove testGetAudioTracksWithNoCurrentItem test - Remove testGetAudioTracksWithNoAsset test - These tests are no longer needed after refactoring to use assertions instead of nil checks
…/flutter_packages into 28-oct-platform-avfoundation
Cherry-picked from upstream PR flutter#10313: - Implement getAudioTracks() to retrieve available audio tracks - Implement selectAudioTrack() to switch between tracks - Implement isAudioTrackSupportAvailable() for runtime capability detection - Support both HLS streams and regular video files - Add comprehensive tests for audio track functionality - Update Pigeon definitions for audio track interface - Bump minimum OS requirements (iOS 13+, macOS 10.15+) - Bump version to 2.9.0 Source: flutter#10313
|
any update on this guys ? 😄 i'm willing to quickly address any comments and make required changes. please do the needful from your side and support in getting this PR landed. |
@nateshmbhat I have asked you several times on these PRs to stop pinging people for updates/reviews. We have a regular process for following up on reviews, and will handle reminders within the team as necessary.
Delays in review happen because everyone involved in the reviews has a lot of work they are balancing. The problem is not that the Flutter team does not understand what their jobs entail, and implying otherwise is disrespectful to the team. |
tarrinneal
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.
Seems like some of the repo lints have changed since you uploaded this. I noted a couple, but you'll need to update the formatting also.
My approval is for the dart code only. All darwin code will need approval from a member of the ios team before this can land.
packages/video_player/video_player_avfoundation/lib/src/avfoundation_video_player.dart
Outdated
Show resolved
Hide resolved
packages/video_player/video_player_avfoundation/lib/src/avfoundation_video_player.dart
Outdated
Show resolved
Hide resolved
…/flutter_packages into 28-oct-platform-avfoundation
AVFoundation Platform PR for : #9925
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 under[^1].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 under[^1].///).