Search code examples
iosvideoviewavfoundationmpmediaplayercontroller

Control buttons in AVPlayer and frame


I have to play a series of videos in my app. I am using AVQueuePlayer to play the videos using the code:

AVQueuePlayer *queuePlayer = [[AVQueuePlayer alloc] initWithItems:items];
AVPlayerLayer *myPlayerLayer  = [AVPlayerLayer playerLayerWithPlayer:queuePlayer];
myPlayerLayer.frame = CGRectMake(0, 0, 320, 350);
[self.view.layer addSublayer:myPlayerLayer];
[self.queuePlayer play];

I am facing two issues.

  1. When the video plays, the frame of player is not according to the given values(i.e. 0, 0, 320, 350).

  2. No control buttons(volume,play,stop, forward etc) are being showed as they are shown when we play video with MPMediaPlayer. Am i missing something for both cases? (I am using AVFoundation for the first time so these questions may seem stupid).

Thanks in advance.


Solution

  • When the video plays, the frame of player is not according to the given values(i.e. 0, 0, 320, 350).

    Apple's sample code doesn't use -playerLayerWithPlayer:. It creates a UIView subclass whose layer is an AVPlayerLayer. Perhaps there's a reason for that. I do that in my code and it works great. Take a look at the AVPlayerDemo code and try doing it that way.

    No control buttons(volume,play,stop, forward etc) are being showed as they are shown when we play video with MPMediaPlayer. Am i missing something for both cases? (I am using AVFoundation for the first time so these questions may seem stupid).

    AVPlayer does not provide these for you. That's what MPMoviePlayerController is for. If you want controls and you want to use AVPlayer, you'll need to create and manage the controls yourself.