gpt4 book ai didi

ios - UIImagePicker 中所选视频的方向

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:19:02 25 4
gpt4 key购买 nike

如何获取从 UIImagepickerController 中的图库中选择的视频的方向?

UIImagePickerController * videoRecorder = [[UIImagePickerController alloc] init];

videoRecorder.delegate = self;
videoRecorder.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
videoRecorder.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie, nil];
[self presentViewController:videoRecorder animated:YES completion:nil];

最佳答案

ALAssetsLibrary 获取您的 AVAsset 并使用以下类别:

@interface ALAssetsLibrary (VideoOrientation)

+ (UIInterfaceOrientation)orientationForTrack:(AVAsset *)asset;

@end


@implementation ALAssetsLibrary (VideoOrientation)


+ (UIInterfaceOrientation)orientationForTrack:(AVAsset *)asset
{
NSArray *videoAssets = [asset tracksWithMediaType:AVMediaTypeVideo];

if (!videoAssets.count)
{
NSLog(@"No video assets found.");
return UIInterfaceOrientationPortrait;
}

// Get the video track.
AVAssetTrack *videoTrack = [videoAssets objectAtIndex:0];

CGSize size = [videoTrack naturalSize];
CGAffineTransform preferredTransform = [videoTrack preferredTransform];

// Return interface orientation based on
// the preferred transform and size of the video.
if (size.width == preferredTransform.tx &&
size.height == preferredTransform.ty)
{
return UIInterfaceOrientationLandscapeRight;
}
else if (preferredTransform.tx == 0 &&
preferredTransform.ty == 0)
{
return UIInterfaceOrientationLandscapeLeft;
}
else if (preferredTransform.tx == 0 &&
preferredTransform.ty == size.width)
{
return UIInterfaceOrientationPortraitUpsideDown;
}
else
{
return UIInterfaceOrientationPortrait;
}
}

@end

关于ios - UIImagePicker 中所选视频的方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21887970/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com