-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[video_player_avfoundation] Fix deprecated tracksWithMediaType usage #10553
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?
[video_player_avfoundation] Fix deprecated tracksWithMediaType usage #10553
Conversation
|
It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging. If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group. |
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 addresses the deprecation of tracksWithMediaType: by migrating to loadTracksWithMediaType:completionHandler: for newer iOS/macOS versions and providing backward compatibility for older OS versions. The changes correctly update the CHANGELOG.md and pubspec.yaml files. The core logic in FVPVideoPlayer.m effectively handles the API transition using @available checks and diagnostic pragmas. However, there are a couple of areas for improvement regarding type specificity and error handling in the Objective-C code.
| * Resolve `tracksWithMediaType:` deprecations. | ||
| * Use `loadTracksWithMediaType:completionHandler:` for iOS 15.0+/macOS 12.0+. | ||
|
|
||
| * ## 2.8.8 |
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.
| // Do not use video composition when it is not needed. | ||
| if (CGAffineTransformIsIdentity(self->_preferredTransform)) { | ||
| return; | ||
| void (^processVideoTracks)(NSArray *) = ^(NSArray *tracks) { |
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.
For better type safety and clarity, consider specifying the type of the tracks array in the processVideoTracks block. The loadTracksWithMediaType:completionHandler: already provides NSArray<AVAssetTrack *> *.
| void (^processVideoTracks)(NSArray *) = ^(NSArray *tracks) { | |
| void (^processVideoTracks)(NSArray<AVAssetTrack *> *) = ^(NSArray<AVAssetTrack *> *tracks) { |
| NSError *_Nullable error) { | ||
| if (error == nil && tracks != nil) { | ||
| processVideoTracks(tracks); | ||
| } |
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 completion handler for loadTracksWithMediaType:completionHandler: checks for error == nil, but if an error occurs, it is not handled or logged. It's good practice to at least log the error to aid in debugging, even if no further action is taken.
if (error == nil && tracks != nil) {
processVideoTracks(tracks);
} else if (error != nil) {
NSLog(@"Error loading tracks: %@", error);
}
fixes Issue #173092
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].///).Description
tracksWithMediaType:API usage that causes compilation warnings on iOS 18/macOS 15.Changes
loadTracksWithMediaType:completionHandler:for iOS 15.0+/macOS 12.0+