How to get video frame of the AVPlayer?

Andrey Banshchikov picture Andrey Banshchikov · Aug 23, 2012 · Viewed 22.6k times · Source

I have PlayerView class for displaying AVPlayer's playback. Code from documentation.

#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>

@interface PlayerView : UIView
@property (nonatomic) AVPlayer *player;
@end

@implementation PlayerView
+ (Class)layerClass {
    return [AVPlayerLayer class];
}
- (AVPlayer*)player {
    return [(AVPlayerLayer *)[self layer] player];
}
- (void)setPlayer:(AVPlayer *)player {
    [(AVPlayerLayer *)[self layer] setPlayer:player];
}
@end

I set up my AVPlayer (contains video asset with size 320x240) in this PlayerView (with frame.size.width = 100, frame.size.height = 100) and my video is resized. How can i get size of video after adding in PlayerView?

Answer

Andrey Banshchikov picture Andrey Banshchikov · Sep 25, 2013

In iOS 7.0 added new feature:

AVPlayerLayer has property videoRect.