简体   繁体   English

设置AVPlayerLayer VideoGravity适用于模拟器,而不适用于iPad

[英]Setting AVPlayerLayer VideoGravity works on Simulator, not on iPad

I'm currently developing a video player for streamed-content using the AVPlayer Framework. 我目前正在使用AVPlayer Framework为流内容开发视频播放器。 I stumbled across the AVPlayerLayer's VideoGravity String-Property which would allow me to set the players Scaling/Resizing Mode to different values. 我偶然发现了AVPlayerLayer的VideoGravity String-Property,它允许我将玩家缩放/调整模式设置为不同的值。

In order to provide the user with the scaling-features known from the default player, I've set up a method that would execute the following code: 为了向用户提供默认播放器中已知的缩放功能,我设置了一个执行以下代码的方法:

AVPlayerLayer *layer = (AVPlayerLayer *)[self.videoContainer layer];

if([layer.videoGravity isEqualToString:AVLayerVideoGravityResizeAspect])
    layer.videoGravity = AVLayerVideoGravityResizeAspectFill;
else 
    layer.videoGravity = AVLayerVideoGravityResizeAspect;

This works very well in the Simulator, but somehow not on my iPad 2 with iOS 5.0.1 installed. 这在模拟器中运行得很好,但不知何故不能在安装了iOS 5.0.1的iPad 2上运行。

Has anyone experienced similar issues? 有没有人遇到类似的问题? Is this a known iOS Bug with 5.0.1? 这是一个已知的iOS Bug 5.0.1吗? Is there a better approach of implementing scaling / resizing with AVPlayerLayer? 有没有更好的方法来实现AVPlayerLayer的缩放/调整大小?

Any ideas/tips/help and recommendations are greatly appreciated, 任何想法/提示/帮助和建议都非常感谢,

Thanks, 谢谢,

Sam 山姆

Setting the bounds will internally setNeedsLayout . 设置边界将在内部setNeedsLayout You must call this your self if you only change the gravity. 如果你只改变引力,你必须称之为自己。 A call to setNeedsDisplay to force a re-draw couldn't hurt either, although I imagine AVPlayerLayer is updating the layer contents so frequently that it won't matter. 调用setNeedsDisplay强制重新绘制也不会有任何影响,尽管我认为AVPlayerLayer正在频繁更新图层内容以至于无关紧要。

EDIT: Your name is twice as good as mine! 编辑:你的名字是我的两倍!

i finally managed to fix my issue by exchanging the above statement with the following... 我终于通过以下方式交换上述声明来解决我的问题...

    if (self.player.status == AVPlayerStatusReadyToPlay) {
    if([((AVPlayerLayer *)[self.videoContainer layer]).videoGravity isEqualToString:AVLayerVideoGravityResizeAspect])
        ((AVPlayerLayer *)[self.videoContainer layer]).videoGravity = AVLayerVideoGravityResizeAspectFill;
    else 
        ((AVPlayerLayer *)[self.videoContainer layer]).videoGravity = AVLayerVideoGravityResizeAspect;

    ((AVPlayerLayer *)[self.videoContainer layer]).bounds = ((AVPlayerLayer *)[self.videoContainer layer]).bounds;
}

setting the AVPlayerLayer's bounds to the AVPlayerLayer's bound seemed to do the trick. 将AVPlayerLayer的边界设置为AVPlayerLayer的边界似乎可以解决问题。 although i don't really get why. 虽然我不明白为什么。

however: hurray for working solution. 然而:欢呼工作解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM