简体   繁体   中英

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

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!

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. although i don't really get why.

however: hurray for working solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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