Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting AVPlayerLayer VideoGravity works on Simulator, not on iPad

I'm currently developing a video player for streamed-content using the 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.

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.

Has anyone experienced similar issues? Is this a known iOS Bug with 5.0.1? Is there a better approach of implementing scaling / resizing with AVPlayerLayer?

Any ideas/tips/help and recommendations are greatly appreciated,

Thanks,

Sam

like image 314
samsam Avatar asked Mar 23 '12 09:03

samsam


1 Answers

Setting the bounds will internally 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.

EDIT: Your name is twice as good as mine!

like image 137
Sam Avatar answered Nov 13 '22 09:11

Sam