1.在需要創(chuàng)建播放器的界面添加頭文件#import "AVFoundation/AVFoundation.h"
/**
?設(shè)置視頻播放
?*/
- (void)setupVideoPlayer{
// 創(chuàng)建url
//設(shè)置本地視頻url
//? ? NSString *myFilePath = [[NSBundle mainBundle]pathForResource:@"movies"ofType:@"mp4"];
//? ? NSString *webVideoPath = [NSURL fileURLWithPath:myFilePath]
//設(shè)置網(wǎng)絡(luò)視頻url
? ? NSString *webVideoPath = @"https://vdse.bdstatic.com//19b5482c80fe2129b3b65d7689aaf886.mp4";
? ? NSURL*webVideoUrl = [NSURL URLWithString:webVideoPath];
? ? AVPlayerItem*videoItem = [[AVPlayerItem alloc]initWithURL:webVideoUrl];
? ? AVPlayer*player = [AVPlayer playerWithPlayerItem:videoItem];
? ? player.volume=0;
? ? AVPlayerLayer*playerLayer = [AVPlayerLayer playerLayerWithPlayer:player];
? ? playerLayer.backgroundColor = [UIColor whiteColor].CGColor;
? ? playerLayer.videoGravity =AVLayerVideoGravityResizeAspectFill;
? ? playerLayer.frame=self.view.bounds;
? ? [self.view.layer insertSublayer:playerLayer atIndex:0];
? ? [player play];
}