Avplayerlayer Shows Black Screen But Sound Is Working

AVPlayer on Swift app shows a black screen but plays audio when playing video

The problem is with the video file itself / the encoding.

Deceptively, the Quicktime ".mov" format is not a video codec, but rather audio/video container format that can contain video and audio (and some other things) in any number of compression codecs (h.264, mpeg2, ProRes, MJPEG, AAC, mp3, etc.) … Your files don't work because they include video compressed with a codec which iOS does not support.

From @alexkent in this SO answer on another post.

I don't think a .mov is necessarily not going to work for you, but you'd have to make sure it was encoded in a way that is iOS-compatible. So as you mentioned in the comments, using .mp4 ensures the video is encoded in an iOS-compatible fashion.

iOS 10 - AVPlayer shows black screen when playing video

Thanks for your replies! I just found that, for some reason in iOS 10 the viewDidLayoutSubviews did not get called as it was in iOS 9. Actually I was setting the player layer's frame in the viewDidLayoutSubviews method. Since it didn't get called, I was not able to see the player on screen. What I did was, set the player layer's frame in the loadPlayer method above.And it works fine. Thanks! Hope this helps someone.

EDIT

This is the line of code that I moved from viewDidLayoutSubviews to my loadPlayer method and it worked:

self.playerLayer.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);

AVPlayer blank video: playing sound but no video

In case anyone encounters this issue, the problem seems related to an iOS bug. The problem doesn't occur on iOS 8/9 devices, only on new iOS 10 devices. Starting with iOS 10.2, the problem vanishes.

Unfortunately, still no programmatic solution for 10.0.x or 10.1.x.

AVPlayerViewController show black screen some times

After so many time.. I found solution.

The problem was that I wasn't cleaning AVPlayer inside AVPlayerController. And I also added New instance inside a DispachQueue.

That's new code:

self.videoPlayerViewController?.player?.pause()
self.videoPlayerViewController?.player = nil
self.videoPlayerViewController = nil
self.videoPlayerViewController = AVPlayerViewController()
self.videoPlayerViewController?.player = viewModel.avPlayer

And after I added in viewController:

if let avController = self.videoPlayerViewController {
DispatchQueue.main.async { [weak self] in
if let strongSelf = self {
strongSelf.add(avController, in: strongSelf.playerView)
avController.player?.play()
}
}
} else {
// Error
}

I hope it could help someone!!



Related Topics



Leave a reply



Submit