@property (nonatomic, retain, nullable) AVPlayer *player;
NSString *urlStr= [[NSBundle mainBundle]pathForResource:@"demo.mp4" ofType:nil];
NSURL *url=[NSURL fileURLWithPath:urlStr];
AVPlayerItem *playerItem=[AVPlayerItem playerItemWithURL:url];
_player=[AVPlayer playerWithPlayerItem:playerItem];
//没这句话会死很久的,,,,
AVPlayerLayer *playerLayer=[AVPlayerLayer playerLayerWithPlayer:self.player];
playerLayer.frame = self.view.bounds;
[self.view.layer addSublayer:playerLayer];
[self.player play];
本文介绍了如何在iOS应用中使用AVPlayer播放本地视频文件。通过设置AVPlayer的播放源为NSBundle获取到的本地资源路径,并创建AVPlayerLayer将其添加到视图层级中实现视频播放。
4630

被折叠的 条评论
为什么被折叠?



