1.在需要创建播放器的界面添加头文件#import "AVFoundation/AVFoundation.h"
/**
设置视频播放
*/
- (void)setupVideoPlayer{
// 创建url
//设置本地视频url
// NSString *myFilePath = [[NSBundle mainBundle]pathForResource:@"movies"ofType:@"mp4"];
// NSString *webVideoPath = [NSURL fileURLWithPath:myFilePath]
//设置网络视频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];
}
网友评论