AVPlayer Full Screen
Asked Answered
L

2

8

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];
Lashondalashonde answered 12/3, 2014 at 4:58 Comment(0)
S
6

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:

Sabrina answered 12/3, 2014 at 5:2 Comment(0)
T
6

For future reference iOS 8 AVKit has the AVPlayerViewController class available that will wrap a AVPlayer and has the standard MPMoviePlayerController class controls.

AVPlayerViewController

AVPlayerViewController * filePlayerViewController = [AVPlayerViewController alloc];
//Show the controls
filePlayerViewController.showsPlaybackControls = true;
AVPlayer * filePlayer = [AVPlayer playerWithURL:[NSURL fileURLWithPath:self.videoFile.localURL]];
filePlayerViewController.player = self.filePlayer;
Taft answered 10/7, 2015 at 2:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.