Question

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];
Was it helpful?

Solution

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:

OTHER TIPS

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;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top