Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
## 2.8.8
## 2.8.8+1

* Resolve `tracksWithMediaType:` deprecations.
* Use `loadTracksWithMediaType:completionHandler:` for iOS 15.0+/macOS 12.0+.

* ## 2.8.8

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The line * ## 2.8.8 appears to be a formatting error. It introduces a nested heading with an asterisk. It should likely be ## 2.8.8 without the asterisk, or the new entries should be placed directly under the existing ## 2.8.8 heading.

Suggested change
* ## 2.8.8
## 2.8.8


* Refactors Dart internals for maintainability.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,32 +82,52 @@ - (instancetype)initWithPlayerItem:(AVPlayerItem *)item
AVAsset *asset = [item asset];
void (^assetCompletionHandler)(void) = ^{
if ([asset statusOfValueForKey:@"tracks" error:nil] == AVKeyValueStatusLoaded) {
NSArray *tracks = [asset tracksWithMediaType:AVMediaTypeVideo];
if ([tracks count] > 0) {
AVAssetTrack *videoTrack = tracks[0];
void (^trackCompletionHandler)(void) = ^{
if (self->_disposed) return;
if ([videoTrack statusOfValueForKey:@"preferredTransform"
error:nil] == AVKeyValueStatusLoaded) {
// Rotate the video by using a videoComposition and the preferredTransform
self->_preferredTransform = FVPGetStandardizedTransformForTrack(videoTrack);
// Do not use video composition when it is not needed.
if (CGAffineTransformIsIdentity(self->_preferredTransform)) {
return;
void (^processVideoTracks)(NSArray *) = ^(NSArray *tracks) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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

Suggested change
void (^processVideoTracks)(NSArray *) = ^(NSArray *tracks) {
void (^processVideoTracks)(NSArray<AVAssetTrack *> *) = ^(NSArray<AVAssetTrack *> *tracks) {

if ([tracks count] > 0) {
AVAssetTrack *videoTrack = tracks[0];
void (^trackCompletionHandler)(void) = ^{
if (self->_disposed) return;
if ([videoTrack statusOfValueForKey:@"preferredTransform"
error:nil] == AVKeyValueStatusLoaded) {
// Rotate the video by using a videoComposition and the preferredTransform
self->_preferredTransform = FVPGetStandardizedTransformForTrack(videoTrack);
// Do not use video composition when it is not needed.
if (CGAffineTransformIsIdentity(self->_preferredTransform)) {
return;
}
// Note:
// https://developer.apple.com/documentation/avfoundation/avplayeritem/1388818-videocomposition
// Video composition can only be used with file-based media and is not supported for
// use with media served using HTTP Live Streaming.
AVMutableVideoComposition *videoComposition =
[self getVideoCompositionWithTransform:self->_preferredTransform
withAsset:asset
withVideoTrack:videoTrack];
item.videoComposition = videoComposition;
}
// Note:
// https://developer.apple.com/documentation/avfoundation/avplayeritem/1388818-videocomposition
// Video composition can only be used with file-based media and is not supported for
// use with media served using HTTP Live Streaming.
AVMutableVideoComposition *videoComposition =
[self getVideoCompositionWithTransform:self->_preferredTransform
withAsset:asset
withVideoTrack:videoTrack];
item.videoComposition = videoComposition;
}
};
[videoTrack loadValuesAsynchronouslyForKeys:@[ @"preferredTransform" ]
completionHandler:trackCompletionHandler];
};
[videoTrack loadValuesAsynchronouslyForKeys:@[ @"preferredTransform" ]
completionHandler:trackCompletionHandler];
}
};

// Use the new async API on iOS 15.0+/macOS 12.0+, fall back to deprecated API on older
// versions
if (@available(iOS 15.0, macOS 12.0, *)) {
[asset loadTracksWithMediaType:AVMediaTypeVideo
completionHandler:^(NSArray<AVAssetTrack *> *_Nullable tracks,
NSError *_Nullable error) {
if (error == nil && tracks != nil) {
processVideoTracks(tracks);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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);
                       }

}];
} else {
// For older OS versions, use the deprecated API with warning suppression
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
NSArray *tracks = [asset tracksWithMediaType:AVMediaTypeVideo];
#pragma clang diagnostic pop
processVideoTracks(tracks);
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: video_player_avfoundation
description: iOS and macOS implementation of the video_player plugin.
repository: https://github.com/flutter/packages/tree/main/packages/video_player/video_player_avfoundation
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22
version: 2.8.8
version: 2.8.8+1

environment:
sdk: ^3.9.0
Expand Down