2
我有一個容器UIView,名爲videoView
。我將AVPLayerLayer添加到該視圖。我不知道如何將videoView
調整爲與avplayer圖層相同的比例。使用videoGravity
沒有預期的效果。根據視頻的高寬比調整AVPlayerItem容器視圖的大小
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];
我正在使用autolayout,我的佈局將適應_videoView的高度變化。
謝謝!加上這個答案我得到它的工作:http://stackoverflow.com/a/34643565/1392515 – stackOverFlew