AVPlayer Video Gravity Positioning?

In my application, I created a custom video player using AVPlayer. This works great and no problem. However, I allow the gravity of the video to be AVPlayerchanged by double-clicking.

When it is changed to AVPlayerGravityResizeAspect, the video is centered in the middle. Is there a way to make a video image of the same size (resize, do not resize the fill), but move it to the bottom or top 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;
        }
    }
}
+4
source share
1 answer

, . , , - , . , , , , - .

+2

Source: https://habr.com/ru/post/1536374/


All Articles