AVPlayer Full Screen

user3231429 picture user3231429 · Mar 12, 2014 · Viewed 13.5k times · Source

i'm using AVPlayer in my apps instead MPMoviePlayerController since i want to put the player as sublayer. However i need control like play, pause, search, and full screen. How do i get that button in AVPlayer? This is how i put the player:

    AVURLAsset *avasset = [[AVURLAsset alloc] initWithURL:URL1 options:nil];

    AVPlayerItem *item = [[AVPlayerItem alloc] initWithAsset:avasset];
    player = [[[AVPlayer alloc] initWithPlayerItem:item]retain];

    playerLayer = [AVPlayerLayer playerLayerWithPlayer:player];
    CGSize size = self.view.bounds.size;
    float x = size.width/2.0-187.0;
    float y = size.height/2.0 - 125.0;

    playerLayer.frame = CGRectMake(x, y, 474, 320);
    [playerLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
    [self.view.layer addSublayer:playerLayer];
    [player play];

Answer

Michael Dautermann picture Michael Dautermann · Mar 12, 2014

You'll have to provide your own buttons.

For play and pause there are direct API's in AVPlayer.

For full screen… well… you know where you are drawing: you just need to size your UIWindow and corresponding UIView & layer to be full size.

For search, you do have methods like seekToTime: