播放视频
2015-08-27 19:25
369 查看
//初始化url
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"abc" ofType:@"mp4"]];
//初始化播放视频
moviePlayer =[[MPMoviePlayerController alloc]initWithContentURL:url];
[self.view addSubview:moviePlayer.view];
moviePlayer.view.frame =CGRectMake(0, 0, self.view.frame.size.width, self.view.bounds.size.height*8/16);
//控制模式
moviePlayer.controlStyle=MPMovieControlStyleNone;
//开始播放
[moviePlayer play];
UIButton *btn =[UIButton buttonWithType:UIButtonTypeCustom];
[btn setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
[btn setTitleColor:[UIColor redColor] forState:UIControlStateSelected];
[btn setTitle:@"" forState:UIControlStateNormal];
btn.frame =CGRectMake(0, 0, self.view.frame.size.width, self.view.bounds.size.height*8/16);
[btn addTarget:self action:@selector(btnAct:) forControlEvents:(UIControlEventTouchUpInside)];
btn.tag = 110;
// moviePlayer.view.layer.transform=CATransform3DMakeRotation(M_PI, .5, 0, 1);
[moviePlayer.view addSubview:btn];
}
- (void)btnAct:(UIButton *)btn{
if (btn.selected) {
[self play];
}else{
[self paush];
}
}
- (void)play{
UIButton *button = (UIButton*)[moviePlayer.view viewWithTag:110];
button.selected = !button.selected;
[moviePlayer play];
}
- (void)paush{
UIButton *button = (UIButton*)[moviePlayer.view viewWithTag:110];
button.selected = !button.selected;
[moviePlayer pause];
}
button点击事件可以实现随意点击,实现播放,暂停功能
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"abc" ofType:@"mp4"]];
//初始化播放视频
moviePlayer =[[MPMoviePlayerController alloc]initWithContentURL:url];
[self.view addSubview:moviePlayer.view];
moviePlayer.view.frame =CGRectMake(0, 0, self.view.frame.size.width, self.view.bounds.size.height*8/16);
//控制模式
moviePlayer.controlStyle=MPMovieControlStyleNone;
//开始播放
[moviePlayer play];
UIButton *btn =[UIButton buttonWithType:UIButtonTypeCustom];
[btn setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
[btn setTitleColor:[UIColor redColor] forState:UIControlStateSelected];
[btn setTitle:@"" forState:UIControlStateNormal];
btn.frame =CGRectMake(0, 0, self.view.frame.size.width, self.view.bounds.size.height*8/16);
[btn addTarget:self action:@selector(btnAct:) forControlEvents:(UIControlEventTouchUpInside)];
btn.tag = 110;
// moviePlayer.view.layer.transform=CATransform3DMakeRotation(M_PI, .5, 0, 1);
[moviePlayer.view addSubview:btn];
}
- (void)btnAct:(UIButton *)btn{
if (btn.selected) {
[self play];
}else{
[self paush];
}
}
- (void)play{
UIButton *button = (UIButton*)[moviePlayer.view viewWithTag:110];
button.selected = !button.selected;
[moviePlayer play];
}
- (void)paush{
UIButton *button = (UIButton*)[moviePlayer.view viewWithTag:110];
button.selected = !button.selected;
[moviePlayer pause];
}
button点击事件可以实现随意点击,实现播放,暂停功能
相关文章推荐
- Java LinqCollection 仿Linq的list常用函数
- 各种页面高度
- linux中root密码忘了怎么办?
- NOIP 2014 day1第二题 联合权值
- Metasploit(三)--Msfcli命令
- PIC16F883单片机EUSART串口通信
- hdu 5311 Hidden String (dfs)
- Cheering up the Cows,2008nov,usaco
- javascript float转int
- Vector Quantization(学习Free Mind知识整理)
- Struts2笔记——ONGL表达式语言
- Struts2笔记——ONGL表达式语言
- GCD和NSOperation多线程技术
- 【转】CentOS上安装 jdk:rpm安装和源码安装
- LCS 最长公共子序列
- Eclipse技巧:[5]eclipse js提示
- 老板,你知道APP是怎么死的吗?
- 0002 手动定制原版 Win7 操作系统(一)
- Java的向上转型与向下转型
- hdu 1160 FatMouse's Speed(最长递减子序列 (加强版) )