Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AVPlayer Video Gravity Positioning?

In my application, I have created a custom video player using AVPlayer. This works great, and there are no problems. However, I allow the AVPlayer video gravity to be changed by a double tap.

When it is changed to AVPlayerGravityResizeAspect, the video is centered in the middle. Is there any way to make the video stay the same size (resize aspect, not resize aspect fill), but move it to the bottom or top of the AVPlayer?

- (IBAction)zoomTapped:(id)sender {
    if (self.player.status == AVPlayerStatusReadyToPlay) {
        if ([((AVPlayerLayer *)[self.playerView layer]).videoGravity isEqualToString : AVLayerVideoGravityResizeAspect]) {
            [self.zoomButton setImage:[UIImage imageNamed:@"zoom-out.png"] forState:UIControlStateNormal];
            ((AVPlayerLayer *)[self.playerView layer]).videoGravity = AVLayerVideoGravityResizeAspectFill;
        }
        else {
            [self.zoomButton setImage:[UIImage imageNamed:@"zoom-in.png"] forState:UIControlStateNormal];
            ((AVPlayerLayer *)[self.playerView layer]).videoGravity = AVLayerVideoGravityResizeAspect;

            ((AVPlayerLayer *)[self.playerView layer]).bounds = ((AVPlayerLayer *)[self.playerView layer]).bounds;
        }
    }
}
like image 637
Josue Espinosa Avatar asked Apr 14 '14 02:04

Josue Espinosa


1 Answers

No, that's not one of your choices. The three gravity choices you get are the three gravity choices you get. However, there is no need for such a feature, because you can position the player layer itself wherever you like, so you can position it at the bottom or top in relation to some view or layer.

like image 103
matt Avatar answered Nov 14 '22 02:11

matt