1

I am trying to set the videogravity on an avplayerlayer. When I set the player layer like so:

[(AVPlayerLayer *)[self layer] setVideoGravity:AVLayerVideoGravityResizeAspectFill]

The video looks like it drops on the view (some sort of animation effect). Is there any way to avoid this effect? FYI, I've tried assigning the avplayer to the layer before and after setting the gravity and there is no different. When I don't set gravity, the video appears as I want it to (without any drop on screen animation).

flynn
  • 1,572
  • 2
  • 12
  • 26
  • possible duplicate of [Disabling implicit animations in -\[CALayer setNeedsDisplayInRect:\]](http://stackoverflow.com/questions/2244147/disabling-implicit-animations-in-calayer-setneedsdisplayinrect) – David Berry Apr 25 '14 at 18:38
  • @David, if it was simply related to just the layer (I already tried the approach from your link and it didn't work), then why do I see the animation only when I set the video gravity? – flynn Apr 25 '14 at 18:54
  • Are you trying to change the gravity while the layer is displayed? – David Berry Apr 25 '14 at 18:58
  • How can I change it before? – flynn Apr 25 '14 at 19:01
  • If I have the view set in my storyboard and then I add the layer to the view programmatically. – flynn Apr 25 '14 at 19:03
  • 3
    Answering that is going to mean seeing a lot more of your code than just the `setVideoGravity:` call. But basically make sure the setVideoGravity call is before you add the view/layer to the view/layer hierarchy. – David Berry Apr 25 '14 at 19:03
  • Thanks @david. You were right, the view was already displayed, which looks like the reason for the animation! I fixed it by setting the videogravity before calling the addsublayer method – flynn Apr 25 '14 at 19:22

1 Answers1

1
AVPlayerLayer *vlayer;
vlayer.speed = isAnimated ? 1 : 999;
vlayer.videoGravity = AVLayerVideoGravityResizeAspect;
Roman Solodyashkin
  • 799
  • 12
  • 17