gpt4 book ai didi

ios - Avplayer 有时显示黑屏但声音很好

转载 作者:可可西里 更新时间:2023-11-01 04:00:06 26 4
gpt4 key购买 nike

我正在使用 AVPlayer 和 AVPlayerViewController。我在视频中添加水印后正在播放视频。有时工作正常,但有时只显示黑屏,两种情况下音频都正常。

vPlayer = [AVPlayer playerWithURL:_videoFilePath];
// create a player view controller
AVPlayerViewController *controller = [[AVPlayerViewController alloc]init];
controller.videoGravity=AVLayerVideoGravityResizeAspect;
controller.player = vPlayer;
[vPlayer seekToTime:kCMTimeZero];

// show the view controller
[self addChildViewController:controller];
[vPlayer play];
controller.view.frame =_imgForVidFrame.frame;
[self.view addSubview:controller.view];

最佳答案

确保 _imgForVidFrame.frame 每次都返回正确的帧!您可以在该行放置断点以检查它是否返回正确的大小!

你的最后一行应该是 [self.view addSubview:controller.view]; 而不是 controller.view.frame =_imgForVidFrame.frame; 所以交换它!

更新:

然后你可以在没有AVPlayerViewController的情况下做类似下面的事情,

AVPlayer *player = [AVPlayer playerWithURL:_videoFilePath];
AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:player];
playerLayer.frame = self.view.bounds;
[self.view.layer addSublayer:playerLayer];
[player play];

或者你可以呈现 AVPlayerViewController 类似的东西,

 AVPlayer *player = [AVPlayer playerWithURL:_videoFilePath];
AVPlayerViewController *playerViewController = [AVPlayerViewController new];
playerViewController.player = player;
[self presentViewController:playerViewController animated:YES completion:nil];

关于ios - Avplayer 有时显示黑屏但声音很好,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39912848/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com