//由于程序的设计需求,要求实现类似广告banner展示的视频播放效果,也就是用户不能控制视频的播放和停止,播放器将循环播放指定的视频
playerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:@"http://sm.domob.cn/ugc/151397.mp4"]];
playerViewController.view.frame = CGRectMake(0, 64, 320, 100);
[self.view addSubview:playerViewController.view];
player = [playerViewController moviePlayer];
player.controlStyle = MPMovieControlStyleNone;
player.shouldAutoplay = YES;
player.repeatMode = MPMovieRepeatModeOne;
[player setFullscreen:YES animated:YES];
player.scalingMode = MPMovieScalingModeAspectFit;
[player play];
//此按钮是普通的视频播放效果,用户可以控制视频的播放和停止
UIButton *playBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
playBtn.frame = CGRectMake(0, 200, 320, 88);
playBtn.backgroundColor = [UIColor blueColor];
[playBtn addTarget:self action:@selector(play) forControlEvents:UIControlEventTouchUpInside];
[playBtn setTitle:@"presentPlay" forState:UIControlStateNormal];
[self.view addSubview:playBtn];
- (void)play
{
NSURL *url = [NSURL URLWithString:@"http://sm.domob.cn/ugc/151397.mp4"];
MPMoviePlayerViewController *movie = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:movie];
}
DEMO下载地址:http://download.youkuaiyun.com/detail/u011918080/7191617