[video_player_avfoundation] Add video track selection support#11476
[video_player_avfoundation] Add video track selection support#11476nateshmbhat wants to merge 1 commit intoflutter:mainfrom
Conversation
Implements getVideoTracks() and selectVideoTrack() methods for video track (quality) selection using AVFoundation. Video track selection requires iOS 15+ / macOS 12+ for HLS streams. AVFoundation breakout PR for flutter#10688.
There was a problem hiding this comment.
Code Review
This pull request introduces video track selection functionality to the AVFoundation video player plugin, specifically for HLS streams on iOS 15+ and macOS 12+. It adds new native methods to retrieve available video tracks and to select a preferred bitrate. The Dart side integrates these native methods, converting native data structures into VideoTrack objects and providing an API for track selection. New tests have been added to cover this functionality, and the plugin version has been updated to 2.10.0. Feedback suggests improving error handling in getVideoTracks for failed asset variant loading and populating assetTracks for non-HLS videos to ensure consistent track information and avoid dead code on the Dart side.
| AVKeyValueStatus status = | ||
| [urlAsset statusOfValueForKey:kFVPAssetVariantsKey error:&error]; | ||
|
|
||
| if (status == AVKeyValueStatusLoaded) { |
There was a problem hiding this comment.
The implementation of getVideoTracks does not handle the case where loading the asset variants fails. If status is AVKeyValueStatusFailed, the error parameter of statusOfValueForKey:error: will be populated, but it is currently ignored, and the method proceeds to return an empty result. It would be better to check for failure and return a FlutterError to provide better diagnostics to the Dart side.
| } | ||
|
|
||
| FVPNativeVideoTrackData *result = | ||
| [FVPNativeVideoTrackData makeWithAssetTracks:nil |
There was a problem hiding this comment.
The assetTracks parameter is explicitly set to nil here, which means that for non-HLS videos (or HLS videos where variants aren't used), no video track information will be returned. However, the Pigeon definition and the Dart implementation in AVFoundationVideoPlayer.dart (lines 250-271) include logic to handle assetTracks. This results in dead code on the Dart side. Consider populating assetTracks using [urlAsset tracksWithMediaType:AVMediaTypeVideo] to provide consistent track information for all video types, even if they don't support quality selection.
Summary
AVFoundation breakout PR for #10688.
getVideoTracks()andselectVideoTrack()methods using AVFoundationDependency Chain
This PR is third in a series of breakout PRs:
video_player_platform_interface([video_player_platform_interface] Add video track selection support #11474) - pendingvideo_player_android([video_player_android] Add video track selection support #11475) - pendingvideo_player_avfoundation(this PR)video_player+video_player_web(pending - original PR [video_player] : Add video track selection support for Android and iOS #10688 updated)Note: This PR depends on
video_player_platform_interface6.7.0 being published first.Test Plan
VideoPlayerTests.swiftAVFoundationVideoPlayeroverrides