Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting videoGravity to AVLayerVideoGravityResizeAspectFill has no effect on iOS 5.0

Tags:

ios

ios5

avplayer

I have implemented a custom movie player with AVPlayer. On setting the value of videoGravity in AVPlayerLayer to AVLayerVideoGravityResizeAspectFill I see the desired effect in iOS 4.2, 4.3. But somehow on iOS 5.0 it has got no effect. Is anybody seeing a similar issue? Am I doing something wrong?

like image 962
Soumya Das Avatar asked Dec 12 '11 12:12

Soumya Das


2 Answers

On iOS5 you should reset layers bounds after setting videoGravity.

This worked for me:

((AVPlayerLayer *)[self layer]).videoGravity = AVLayerVideoGravityResizeAspectFill;
((AVPlayerLayer *)[self layer]).bounds = ((AVPlayerLayer *)[self layer]).bounds;

EDITED: "self" points to a PlayerView (subclass of UIView) object from example "Putting all together": https://developer.apple.com/library/ios/#documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/02_Playback.html

like image 66
miham Avatar answered Sep 27 '22 20:09

miham


Found the solution to this issue. Tick checkbox "Clip Subviews" in IB for the view with the layer you're going to attach the video player to. Then, set the AVLayerVideoGravityResizeAspectFill of your AVPlayerLayer object. If you don't have the view in IB but you're creating it programmatically, set its clipsToBounds property to YES.

like image 39
carlos_ms Avatar answered Sep 27 '22 21:09

carlos_ms