feat(ios): add audio track selection support for AVFoundation#10313
feat(ios): add audio track selection support for AVFoundation#10313auto-submit[bot] merged 38 commits intoflutter:mainfrom
Conversation
There was a problem hiding this comment.
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.
+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 |
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.
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.
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
...undation/darwin/video_player_avfoundation/Sources/video_player_avfoundation/FVPVideoPlayer.m
Outdated
Show resolved
Hide resolved
| // Skip nil options | ||
| if (!option || [option isKindOfClass:[NSNull class]]) { | ||
| continue; |
There was a problem hiding this comment.
+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
Outdated
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 <31859944+LongCatIsLooong@users.noreply.github.com>
- 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
…/flutter_packages into 28-oct-platform-avfoundation
|
Thanks for the review! I've removed all the AVAssetTrack related code based on your comments. This also simplifies the API to only expose tracks that are actually selectable (HLS MediaSelection tracks) |
LongCatIsLooong
left a comment
There was a problem hiding this comment.
The implementation LGTM, but it seems the tests are not compiling.
| final tracks = <VideoAudioTrack>[]; | ||
|
|
||
| for (final track in nativeData) { | ||
| final String? label = track.commonMetadataTitle ?? track.displayName; |
There was a problem hiding this comment.
Shouldn't displayName be preferred over metadata title, because the display name is potentially localized?
There was a problem hiding this comment.
Also should the fallback happen in the objective c part of this implementation so that we don't have to encode / decode both common metadata title and display name in case both are present?
There was a problem hiding this comment.
Our general direction in the repo is to have logic in Dart when there's not a strong reason to have it on the native side; encoding a couple of short short strings isn't something we would expect to have non-trivial perf impact.
fixed the tests @LongCatIsLooong |
|
Can you resolve the conflicts and merge master? |
LongCatIsLooong
left a comment
There was a problem hiding this comment.
The CI is failing because the changes in the video_player package doesn't have associated CHANGELOG entries:
Changed packages: video_player/video_player,video_player_avfoundation
[0:00] Running for packages/video_player/video_player...
No version change.
Found NEXT; validating next version in the CHANGELOG.
No CHANGELOG change found.
If this PR needs an exemption from the standard policy of listing all changes in the CHANGELOG,
comment in the PR to explain why the PR is exempt, and add (or ask your reviewer to add) the
"override: no changelog needed" label.
Otherwise, please add a NEXT entry in the CHANGELOG as described in the contributing guide.
[0:00] Running for packages/video_player/video_player_avfoundation...
2.8.9 -> 2.9.0
The following packages had errors:
packages/video_player/video_player:
Missing CHANGELOG change
This is the main package changelog which I will update in the main PR once we merge this ios specific PR. |
You will need to either remove the video_player/video_player changes (if that works), or add a |
|
@tarrinneal updated the PR with a fix |
flutter/packages@d80c60e...9010299 2026-01-21 jhy03261997@gmail.com [batch-release] Step2 : Publish packages from the release branch (flutter/packages#10459) 2026-01-21 dpxhfxywang@163.com [two_dimensional_scrollables] optimizes tableview janks with >250k rows (flutter/packages#10738) 2026-01-21 magder@google.com [url_launcher_ios] Migrate XCTest to Swift Testing (flutter/packages#10780) 2026-01-21 edpizzi@gmail.com [in_app_purchase] Fix an issue causing StoreKit 2 transactions remain unfinished (flutter/packages#10656) 2026-01-21 stuartmorgan@google.com [google_maps_flutter] Restructure iOS to prep for SwiftPM (flutter/packages#10839) 2026-01-21 jhy03261997@gmail.com [batch-release] Step3: Adds github action to create a PR to sync changes on the go_router release branch back to the main branch (flutter/packages#10393) 2026-01-21 nateshmbhat1@gmail.com feat(ios): add audio track selection support for AVFoundation (flutter/packages#10313) 2026-01-21 49699333+dependabot[bot]@users.noreply.github.com [dependabot]: Bump androidx.core:core from 1.13.1 to 1.17.0 in /packages/image_picker/image_picker_android/android (flutter/packages#10504) 2026-01-21 38853913+AlexDochioiu@users.noreply.github.com [vector_graphics_compiler] Fix rgb/rgba color parsing to support modern CSS syntax (flutter/packages#10538) 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#181323) flutter/packages@d80c60e...9010299 2026-01-21 jhy03261997@gmail.com [batch-release] Step2 : Publish packages from the release branch (flutter/packages#10459) 2026-01-21 dpxhfxywang@163.com [two_dimensional_scrollables] optimizes tableview janks with >250k rows (flutter/packages#10738) 2026-01-21 magder@google.com [url_launcher_ios] Migrate XCTest to Swift Testing (flutter/packages#10780) 2026-01-21 edpizzi@gmail.com [in_app_purchase] Fix an issue causing StoreKit 2 transactions remain unfinished (flutter/packages#10656) 2026-01-21 stuartmorgan@google.com [google_maps_flutter] Restructure iOS to prep for SwiftPM (flutter/packages#10839) 2026-01-21 jhy03261997@gmail.com [batch-release] Step3: Adds github action to create a PR to sync changes on the go_router release branch back to the main branch (flutter/packages#10393) 2026-01-21 nateshmbhat1@gmail.com feat(ios): add audio track selection support for AVFoundation (flutter/packages#10313) 2026-01-21 49699333+dependabot[bot]@users.noreply.github.com [dependabot]: Bump androidx.core:core from 1.13.1 to 1.17.0 in /packages/image_picker/image_picker_android/android (flutter/packages#10504) 2026-01-21 38853913+AlexDochioiu@users.noreply.github.com [vector_graphics_compiler] Fix rgb/rgba color parsing to support modern CSS syntax (flutter/packages#10538) 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
…ection feature (#9925) ## Description This PR adds comprehensive audio track retrieval and selection support to the video_player package, enabling developers to access detailed information about available audio tracks and switch between them during playback. Breakout PRs: 1. Platform interface : #10171 2. Andrioid : #10312 3. ios : #10313 ### Changes Made #### Core Features - **Added `VideoAudioTrack` model** with comprehensive metadata fields: `id`, `label`, `language`, `isSelected`, `bitrate`, `sampleRate`, `channelCount`, `codec` - **Added [getAudioTracks()]() method** to retrieve all available audio tracks with real metadata - **Added [selectAudioTrack()]() method** to switch between audio tracks during playback - **Updated `VideoPlayerController`** to expose audio track functionality #### Platform Implementations - **Android**: - Real metadata extraction using ExoPlayer's `getCurrentTracks()` API - Robust track selection using `TrackSelectionOverride` with proper error handling - Support for multiple audio formats (AAC, AC3, EAC3, MP3, etc.) - **iOS**: - Metadata extraction from AVFoundation using `AVAssetTrack` for regular videos - HLS stream support using `AVMediaSelectionGroup` for adaptive streams - Proper track selection for both asset tracks and media selection options #### Technical Infrastructure - **Updated Pigeon interfaces** for both Android and iOS with new data structures: - `AudioTrackMessage`, `ExoPlayerAudioTrackData`, `AssetAudioTrackData`, `MediaSelectionAudioTrackData`, `NativeAudioTrackData` - **Enhanced platform interface** with new methods and data classes - **Has native unit tests** for both Android and iOS platforms - **Created demo screen** showcasing audio track functionality with interactive UI ### Demo Features - Interactive video player with audio track selection - Real-time metadata display (bitrate, sample rate, channels, codec) - Support for multiple video sources including HLS streams - Visual indicators for currently selected tracks ## Related Issues Fixes flutter/flutter#59437 ### Testing - Added native unit tests for both Android and iOS - Tested with various video formats and HLS streams - Verified backward compatibility with existing functionality - Demo screen widget for manual testing and validation ### Breaking Changes None - all changes are additive and backward compatible. ## Pre-Review Checklist
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].///).