AVPlay播放视频


@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)