这是我的代码,
@interface ViewController ()
{
AVPlayer *avPlayer;
}
@end
- (void)viewDidAppearBOOL)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];
}
Best Answer-推荐答案 strong>
这真的不应该在任何 iOS 版本上工作,因为
AVPlayer *avPlayer = [AVPlayer playerWithPlayerItem:playerItem];
超出范围并在 viewDidAppear 结束时被释放。
您应该将 AVPlayer 分配给类成员变量,以阻止这种情况发生。
否则视频文件可能有问题。
关于ios - AVPlayer 在 iOS7 中不显示视频,在 iOS8 和 iOS9 上运行良好,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/33360752/
|