Created
March 25, 2014 19:34
-
-
Save r3econ/9769459 to your computer and use it in GitHub Desktop.
ALAssersLibrary category for getting the video's orientation.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface ALAssetsLibrary (VideoOrientation) | |
+ (UIInterfaceOrientation)orientationForTrack:(AVAsset *)asset; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "ALAssetsLibrary+VideoOrientation.h" | |
@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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment