// ---------------第一种视频加载方法——————————————
1.先引入两个框架,第一个框架
#import <AVFoundation/AVFoundation.h>
#import <AVKit/AVKit.h>
2 //获取文件
NSString *str=[[NSBundle mainBundle]pathForResource:@"张韶涵-第一页.mp4" ofType:nil];
NSURL *url=[NSURL fileURLWithPath:str];
//
AVPlayer *play=[AVPlayer playerWithURL:url];
//
AVPlayerLayer*layplay=[AVPlayerLayer playerLayerWithPlayer:play];
//设置尺寸
layplay.frame=CGRectMake(0,0,[UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width);
[self.view.layer addSublayer:layplay];
//播放
[play play];
//---------------第二种——————————————————-------
1.引入框架 #import <AVKit/AVKit.h>
2.设置uibutton
UIButton *playbut=[[UIButton alloc]initWithFrame:CGRectMake(100, CGRectGetMaxY(layplay.frame)+100, 60, 40)];
[self.view addSubview:playbut];
playbut.backgroundColor=[UIColor brownColor];
[playbut setTitle:@"播放" forState:UIControlStateNormal];
[playbut addTarget:self action:@selector(playmodel:) forControlEvents:UIControlEventTouchUpInside];
}
//点击播放按钮进入的方法:-(void)playmodel:(UIButton *)sender{
//获取文件
NSString *path=[[NSBundle mainBundle]pathForResource:@"张韶涵-第一页.mp4" ofType:nil];
NSURL *url=[NSURL fileURLWithPath:path];
AVPlayer *avplayy=[AVPlayer playerWithURL:url];
_avviewplay=[[AVPlayerViewController alloc]init];
_avviewplay.player=avplayy;
//跳转方法
[self presentViewController:_avviewplay animated:YES completion:nil];
来源:oschina
链接:https://my.oschina.net/u/2893325/blog/740038