gpt4 book ai didi

ios - AVPlayer 在 iOS7 中不显示视频,在 iOS8 和 iOS9 上工作正常

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:56:53 25 4
gpt4 key购买 nike

这是我的代码,

@interface ViewController ()
{
AVPlayer *avPlayer;
}
@end

- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
UIView *containerView = [[UIView alloc] initWithFrame:self.view.frame];
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"TestVideo" ofType:@"mp4"];
AVAsset *asset = [AVAsset assetWithURL:[NSURL fileURLWithPath:filepath]];
AVPlayerItem *playerItem = [[AVPlayerItem alloc] initWithAsset:asset];
avPlayer = [AVPlayer playerWithPlayerItem:playerItem];
AVPlayerLayer *avPlayerLayer = [AVPlayerLayer playerLayerWithPlayer:avPlayer];

avPlayerLayer.frame = self.view.frame;
[containerView.layer addSublayer:avPlayerLayer];
[self.view addSubview:containerView];
[avPlayer play];
}

最佳答案

这真的不应该在任何 iOS 版本上工作,因为

AVPlayer *avPlayer = [AVPlayer playerWithPlayerItem:playerItem];

超出范围并在 viewDidAppear 结束时被释放。

您应该将 AVPlayer 分配给类成员变量,以阻止这种情况发生。

否则视频文件可能有问题。

关于ios - AVPlayer 在 iOS7 中不显示视频,在 iOS8 和 iOS9 上工作正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33360752/

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