AVPlayer视频空白但听到声音 [英] AVPlayer Video Blank but Hear Sound
问题描述
我正在从 MPMoviePlayerController
切换到 AVPlayer
,因为我需要对视频交换进行更精细的控制。我正在玩 MPMoviePlayerController
的 .mov
文件播放正常,但切换到 AVPlayer
我听到视频中的音频,但视频只显示我添加 AVPlayerLayer
的视图背景。这是我如何初始化 AVPlayer
。
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];
然后我发出一个。
[self.player play];
视频播放时我听到了音频,但看不到视频。我也尝试将zPosition设置为没有运气。
When the video plays I hear the audio, but see no video. I also tried setting the zPosition to no luck.
playerLayer.zPosition = 1;
推荐答案
发现它是使用<$ c的结果$ C>自动版式。在 viewDidLoad
中, self.playerContainer.bounds
是 CGRectZero
。
Found out it was a result of using AutoLayout
. In the viewDidLoad
the self.playerContainer.bounds
is a CGRectZero
.
我必须在 viewDidAppear
中指定playerLayer帧以匹配playerContainer。
I had to assign the playerLayer frame in the viewDidAppear
to match the playerContainer.
这篇关于AVPlayer视频空白但听到声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!