【问题标题】:resize AVPlayerItem container view based on aspect ratio from video根据视频的纵横比调整 AVPlayerItem 容器视图的大小
【发布时间】:2016-01-31 19:54:45
【问题描述】:

我有一个名为 videoView 的容器 UIView。我在该视图中添加了一个 AVPLayerLayer。我不知道如何将videoView 调整为与 avplayer 层相同的比例。使用videoGravity 并没有达到预期的效果。

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];

我正在使用自动布局,我的布局将适应 _videoView 高度的变化。

【问题讨论】:

    标签: ios objective-c avplayer aspect-ratio


    【解决方案1】:

    videoGravity 不会改变视图的帧,而是用视频填充当前帧。

    我认为您应该在播放之前检查每个视频的 resolution 并调整 videoView 的高度约束(应该是一个 ivar 并约束到 videoView 的宽度)multipliervideoView 宽度应限制为屏幕宽度。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-04-28
    • 2017-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多