MPMoviePlayerViewController的使用
2014-01-23 17:04
381 查看
- (void)viewDidLoad
{
[super viewDidLoad];
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
button.frame = CGRectMake(100, 100, 100, 100);
[button setImage:[UIImage imageNamed:@"1.png"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(play:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
[button setTitle:@"播放" forState:UIControlStateNormal];
}
- (void)play:(UIButton*)button
{
[self playMovie]; //点击button调用视频播放
[playMovie.moviePlayer play];
}
//播放视频
- (void)playMovie
{
NSURL *url = [NSURL URLWithString:@"http://data.vod.itc.cn/?new=/102/196/G3DltnLK1nA73WYpi1XXF3.mp4&plat=3&mkey=dl_snx23d-ILpAMKn0ccasFqgx__OjJL"];
playMovie = [[MPMoviePlayerViewController alloc]initWithContentURL:url];
playMovie.moviePlayer.view.frame = self.view.bounds;
playMovie.moviePlayer.fullscreen = YES;
UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"moviePause.png"]];
imageView.frame = CGRectMake(270, 410, 30, 30);
[playMovie.moviePlayer.view addSubview:imageView]; //这个属性可以在控制栏添加按钮
playMovie.moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
if (playMovie.interfaceOrientation == UIInterfaceOrientationLandscapeLeft || playMovie.interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
playMovie.view.frame = CGRectMake(0, 0, self.view.bounds.size.height, self.view.bounds.size.width); //如果是旋转的话 宽和高大小交换实现屏幕旋转
}else{
playMovie.view.frame = self.view.bounds;
}
[self.view addSubview:playMovie.moviePlayer.view];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerPlaybackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
}
// 视频播放完毕
- (void)moviePlayerPlaybackDidFinish:(NSNotification *)notification {
//此处播放完成做什么事
}
{
[super viewDidLoad];
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
button.frame = CGRectMake(100, 100, 100, 100);
[button setImage:[UIImage imageNamed:@"1.png"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(play:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
[button setTitle:@"播放" forState:UIControlStateNormal];
}
- (void)play:(UIButton*)button
{
[self playMovie]; //点击button调用视频播放
[playMovie.moviePlayer play];
}
//播放视频
- (void)playMovie
{
NSURL *url = [NSURL URLWithString:@"http://data.vod.itc.cn/?new=/102/196/G3DltnLK1nA73WYpi1XXF3.mp4&plat=3&mkey=dl_snx23d-ILpAMKn0ccasFqgx__OjJL"];
playMovie = [[MPMoviePlayerViewController alloc]initWithContentURL:url];
playMovie.moviePlayer.view.frame = self.view.bounds;
playMovie.moviePlayer.fullscreen = YES;
UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"moviePause.png"]];
imageView.frame = CGRectMake(270, 410, 30, 30);
[playMovie.moviePlayer.view addSubview:imageView]; //这个属性可以在控制栏添加按钮
playMovie.moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
if (playMovie.interfaceOrientation == UIInterfaceOrientationLandscapeLeft || playMovie.interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
playMovie.view.frame = CGRectMake(0, 0, self.view.bounds.size.height, self.view.bounds.size.width); //如果是旋转的话 宽和高大小交换实现屏幕旋转
}else{
playMovie.view.frame = self.view.bounds;
}
[self.view addSubview:playMovie.moviePlayer.view];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerPlaybackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
}
// 视频播放完毕
- (void)moviePlayerPlaybackDidFinish:(NSNotification *)notification {
//此处播放完成做什么事
}
相关文章推荐
- MPMoviePlayerViewController和MPMoviePlayerController的使用
- ios-MPMoviePlayerController和MPMoviePlayerViewController的使用
- MPMoviePlayerViewController和MPMoviePlayerController的使用
- MPMoviePlayerViewController和MPMoviePlayerController的使用
- MPMoviePlayerViewController和MPMoviePlayerController的使用
- Swift3 MPMoviePlayerViewController的使用,iOS播放视频
- 使用MPMoviePlayerViewController播放视频
- 使用MPMoviePlayerViewController播放视频--
- iPhone开发之音视频的播放——MPMoviePlayerViewController和AVAutoPlayer的使用
- MPMoviePlayerViewController和MPMoviePlayerController的使用
- 如何使用MPMoviePlayerViewController播放多个视频
- 82 MPMoviePlayerViewController基本使用
- 使用封装号的MPMoviePlayerViewController播放MP4视频
- iOS开发 MPMoviePlayerController和MPMoviePlayerViewController(视频播放)的使用
- MPMoviePlayerViewController的使用方法和横屏显示
- 播放视频音频文件使用 MPMoviePlayerViewController
- iOS播放视频 MPMoviePlayerViewController 和 MPMoviePlayerController 使用说明
- 播放视频音频文件使用 MPMoviePlayerViewController
- ios播放视频文件一般使用 MPMoviePlayerViewController 和 MPMoviePlayerController
- MPMoviePlayerViewController和MPMoviePlayerController的使用