Avplayer fullscreen

I have an AVPlayer used with AVAsset to play videos.

I've added some controls like play, stop, forward, etc.

But how can I switch to full screen mode using a button? I don't want to use MPMoviePlayerController because I don't know how to synchronize the startup time. But how can I just "extend" the current playerView to use fullScreen?

Thank.

+3


source to share


3 answers


  • If AvPlayer has the same frame as the view or window

    • To make an AVPlayer full screen, you must provide a full frame of the window to the AVPlayer layer, rather than rotate the view by pi / 2.
  • If AvPlayer has less view frame or window

    • Create on protocal for parent to change player frame to window frame when user clicks terrain button

    • Rotate view to pi / 2.

create one method and use below code.



-(void)enlarge
{
    if(!_isLandscapeMode)
    {
        [self.landscapeDelegate changeFrameForLandscapeMode:YES];
        [_landscapeMode setImage:[UIImage imageNamed:IMAGE_NAME_PORTRAIT_MODE] forState:UIControlStateNormal];
        _isLandscapeMode=YES;

        self.transform =  CGAffineTransformMakeRotation(M_PI_2);
    }
    else
    {
        [self.landscapeDelegate changeFrameForLandscapeMode:NO];
        _isLandscapeMode=NO;
        [_landscapeMode setImage:[UIImage imageNamed:IMAGE_NAME_LANDSCAPE_MODE] forState:UIControlStateNormal];
        self.transform =  CGAffineTransformMakeRotation(0);
    }
}

      

+3


source


Let's say you have UIViewController

with a fullscreen UIView

You need to use AVPlayerLayer



var player = AVPlayer(playerItem: AVPlayerItem(asset: asset))
var layer = AVPlayerLayer(player: player)
self.view.layer.addSublayer(layer)
layer.frame = CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height)

      

+2


source


I had the same problem. I have added the following lines to my code,

 [playerLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];

      

It will now display full screen.

+1


source







All Articles