简述:MPMoviePlayerController
,MPMoviePlayerViewController
,AVPlayerViewController
三种视频播放器的讲解
效果:
MPMoviePlayerController 密码: yam8
MPMoviePlayerController,在MediaPlayer框架中
#import
播放器可以任意修改播放页面尺寸
代码:(你可以自己设置开始和暂停按钮)
1.先自定义一个全局的MPMoviePlayerController 对象
MPMoviePlayerController *mPMoviePlayerController;
2.视频的播放
mPMoviePlayerController = [[MPMoviePlayerController alloc]initWithContentURL:[NSURL URLWithString:@"http://v.jxvdy.com/sendfile/w5bgP3A8JgiQQo5l0hvoNGE2H16WbN09X-ONHPq3P3C1BISgf7C-qVs6_c8oaw3zKScO78I--b0BGFBRxlpw13sf2e54QA"]];
[self.view addSubview:mPMoviePlayerController.view];
mPMoviePlayerController.view.frame = CGRectMake(0, 100, 414, 300);
[mPMoviePlayerController play];
[mPMoviePlayerController play]; //视频开始播放
[mPMoviePlayerController pause]; //视频暂停播放
效果:
MPMoviePlayerViewController 密码: 4uum
MPMoviePlayerViewController 在MediaPlayer框架中
#import
MPMoviePlayerViewController是一个特殊的视图控制器类,它包含了一个播放器(MPMoviePlayerController)
1.先自定义一个全局的MPMoviePlayerViewController 对象
MPMoviePlayerViewController *mPMoviePlayerViewController;
2.把下面的代码放到跳转播放的按钮方法里面
mPMoviePlayerViewController = [[MPMoviePlayerViewController alloc]initWithContentURL:[NSURL URLWithString:@"http://v.jxvdy.com/sendfile/w5bgP3A8JgiQQo5l0hvoNGE2H16WbN09X-ONHPq3P3C1BISgf7C-qVs6_c8oaw3zKScO78I--b0BGFBRxlpw13sf2e54QA"]];
mPMoviePlayerViewController.view.frame = CGRectMake(0, 100, 414, 300);
[self presentViewController:mPMoviePlayerViewController animated:YES completion:nil];
AVPlayerViewController,iOS9之后新的一个视频播放类,在AVKit框架中 跟MPMoviePlayerViewController一样是一个试图控制器类,但他内部通过与AVPlay搭配来实现播放视频
1.需要导入下面的框架
#import 包含类 AVPlayerViewController
#import 包含类 AVPlayer
2.创建全局的对象
AVPlayerViewController *aVPlayerViewController;
3.写代码
aVPlayerViewController = [[AVPlayerViewController alloc]init];
aVPlayerViewController.player = [[AVPlayer alloc]initWithURL:[NSURL URLWithString:@"http://v.jxvdy.com/sendfile/w5bgP3A8JgiQQo5l0hvoNGE2H16WbN09X-ONHPq3P3C1BISgf7C-qVs6_c8oaw3zKScO78I--b0BGFBRxlpw13sf2e54QA"]];
/**
* 进行视频播放的跳转
*/
UIButton *bofang = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 200, 50)];
[bofang setTitle:@"播放" forState:UIControlStateNormal];
[bofang setBackgroundColor:[UIColor brownColor]];
bofang.center = self.view.center;
[bofang addTarget:self action:@selector(bofang) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview: bofang];
4.播放(模态式的跳转播放)
-(void)bofang
{
[self presentViewController:aVPlayerViewController animated:YES completion:nil];
}
5.这个也可以在当前页面进行播放(对象.player + play来播放)
[aVPlayerViewController.player play];
AVPlayerViewController播放的deno 密码: 92iv
需要导入下面的框架
#import
AVPlayerViewController,iOS9之后新的一个视频播放类,在AVKit框架中
跟MPMoviePlayerViewController一样是一个试图控制器类,但他内部通过与AVPlay搭配来实现播放视频
/*
* AVPlayer播放视频流程
1、创建一个AVPlayerItem对象,每个AVPlayerItem对象,就是一个视频或音频
2、将AVPlayerItem对象放到一个AVPlayer对象,AVPlayer对象负责视频的暂停与开启操作
3、将AVPlayer放到一个AVPlayerLayer对象里,AVPlayerLayer负责视频的一个展示,他可以设置frame
4、将AVPlayLayer放到某试图的layer层
5、播放
*/
代码:
//1 创建AVPlayerItem
AVPlayerItem *playerItem = [[AVPlayerItem alloc]initWithURL:[NSURL URLWithString:@"http://v.jxvdy.com/sendfile/w5bgP3A8JgiQQo5l0hvoNGE2H16WbN09X-ONHPq3P3C1BISgf7C-qVs6_c8oaw3zKScO78I--b0BGFBRxlpw13sf2e54QA"]];
//2.把AVPlayerItem放在AVPlayer上
player = [[AVPlayer alloc]initWithPlayerItem:playerItem];
//3 再把AVPlayer放到 AVPlayerLayer上
AVPlayerLayer *avplayerLayer = [AVPlayerLayer playerLayerWithPlayer:player];
avplayerLayer.frame = CGRectMake(0, 100, 414, 300);
//4 最后把 AVPlayerLayer放到self.view.layer上(也就是需要放置的视图的layer层上)
[self.view.layer addSublayer:avplayerLayer];
/**
* 视频播放按钮
*/
UIButton *bofang = [[UIButton alloc]initWithFrame:CGRectMake(50, CGRectGetMaxY(avplayerLayer.frame)+100, 100, 50)];
[bofang setTitle:@"播放" forState:UIControlStateNormal];
[bofang setBackgroundColor:[UIColor brownColor]];
[bofang addTarget:self action:@selector(bofang) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview: bofang];
/**
* 视频暂停按钮
*/
UIButton *zanting = [[UIButton alloc]initWithFrame:CGRectMake(WIDTH-150, CGRectGetMaxY(avplayerLayer.frame)+100, 100, 50)];
[zanting setTitle:@"播放" forState:UIControlStateNormal];
[zanting setBackgroundColor:[UIColor brownColor]];
[zanting addTarget:self action:@selector(zanting) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview: zanting];
视频开始
-(void)bofang
{
[player play];
}
视频暂停
-(void)zanting
{
[player pause];
}
AVPlayer代码 密码: 6jk9
最后其他人的视频播放
视频文档1
视频文档2