AVPlayer 播放本地文件
2018-12-12 本文已影响10人
会飞的大西瓜v
NSString *str = [[NSBundle mainBundle] resourcePath];
NSString *filePath = [NSString stringWithFormat:@"%@%@",str,@"/ad_video.mp4"];
NSURL *sourceMovieURL = [NSURL fileURLWithPath:filePath];
AVAsset *movieAsset = [AVURLAsset URLAssetWithURL:sourceMovieURL options:nil];
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:movieAsset];
AVPlayer *player = [AVPlayer playerWithPlayerItem:playerItem];
AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:player];
playerLayer.frame = CGRectMake(0, 0, 300, 300);
playerLayer.videoGravity = AVLayerVideoGravityResizeAspect;
[self.layer addSublayer:playerLayer];