I have a container UIView called videoView
. I add a AVPLayerLayer to that view. I do not know how to resize the videoView
to be of the same proportions as the avplayer layer. Using videoGravity
does not have the desired effect.
AVPlayerItem* playerItem = [AVPlayerItem playerItemWithURL:path];
_videoPlayer = [[AVPlayer alloc] initWithPlayerItem:playerItem];
AVPlayerLayer *layer = [AVPlayerLayer layer];
[_avplayerLayer setPlayer:_videoPlayer];
[_avplayerLayer setBackgroundColor:[UIColor whiteColor].CGColor];
[_avplayerLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
[_avplayerLayer setFrame:_videoView.bounds];
[_videoView.layer addSublayer:_avplayerLayer];
I am using autolayout, and my layout would accommodate a change in the height of _videoView.