Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AVPlayer Full Screen

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];
like image 742
user3231429 Avatar asked Mar 12 '14 04:03

user3231429


2 Answers

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:

like image 193
Michael Dautermann Avatar answered Oct 22 '22 17:10

Michael Dautermann


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;
like image 43
Cody Lohse Avatar answered Oct 22 '22 18:10

Cody Lohse