Setting AVPlayerLayer VideoGravity works on Simulator, not on iPad.

I am currently developing a video player for streaming content using the AVPlayer Framework. I came across an AVPlayerLayer VideoGravity String-Property, which would allow me to set the scaling / resizing mode of the players to different values.

To provide the user with the zoom features known from the default player, I have configured a method that will 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 Simulator, but somehow not on my iPad 2 with iOS 5.0.1 installed.

Has anyone encountered similar problems? Is this a known iOS bug with 5.0.1? Is there a better way to implement scaling / resizing using AVPlayerLayer?

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

Thanks,

Sam

+8
ios objective-c avplayer
source share
2 answers

Setting boundaries will be internally setNeedsLayout . You must call it your self if you only change gravity. The call to setNeedsDisplay to force a re-draw did not hurt, although I think that AVPlayerLayer updates the contents of the layer so often that it doesn't matter.

EDIT: Your name is twice as big as mine!

+20
source share

I finally managed to fix my problem 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 borders of AVPlayerLayer to bind to AVPlayerLayer seems to do the trick. although I really don't understand why.

however: cheers for a working solution.

+4
source share

All Articles