AVPlayer Video Blank but Hear Sound

Gary Rudolph picture Gary Rudolph · May 29, 2013 · Viewed 8.2k times · Source

I'm switching from MPMoviePlayerController to AVPlayer as I need finer grained control over video swapping. The .mov file I was playing with MPMoviePlayerController played fine, but after switching to AVPlayer I hear the audio from the video, but the video just shows the view background that I added the AVPlayerLayer to. Here's how I'm initializing the AVPlayer.

self.player = [[AVPlayer alloc] initWithURL:video];

AVPlayerLayer* playerLayer = [AVPlayerLayer playerLayerWithPlayer:self.player];
playerLayer.frame = self.playerContainer.bounds;
[self.playerContainer.layer addSublayer:playerLayer];

Then later I just issue a.

[self.player play];

When the video plays I hear the audio, but see no video. I also tried setting the zPosition to no luck.

playerLayer.zPosition = 1;

Answer

Gary Rudolph picture Gary Rudolph · May 29, 2013

Found out it was a result of using AutoLayout. In the viewDidLoad the self.playerContainer.bounds is a CGRectZero.

I had to assign the playerLayer frame in the viewDidAppear to match the playerContainer.