MPMoviePlayerViewController
按钮中点击时间中:
NSString *s = @"http://hot.vrs.sohu.com/ipad1340910.m3u8";
// s = [s stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
//如果链接中有中文则需要转码
NSURL *url = [NSURL URLWithString:s];
MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc]initWithContentURL:url];
// 注意MPMoviePlayerViewController是控制器对象
MPMoviePlayerController是继承于NSObject的对象,
本质不同,不要混淆了.
[self presentMoviePlayerViewControllerAnimated:mp];
注意:
// 如果是本地视频 , 用fileURLWithPath:
NSString *path = [[NSBundle mainBundle] pathForResource:@"3" ofType:@"mp4"];
//file:// http://
url = [NSURL fileURLWithPath:path];
补充:
// 探索新方法
//
MPMoviePlayerViewController和MPMoviePlayerController.
// 不同点:
MPMoviePlayerController需要自己把自带的view用
setFrame的方法加到视图上.
测试MPMoviePlayerController写一个Demo看看:
OK 发现了另一种实现方式:
-(void)btnAction:(UIButton *)sender{
NSString *s = @"http://hot.vrs.sohu.com/ipad1340910.m3u8";
// s = [s stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:s];
if (_moviePlayer == nil) {
_moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
}else {
[_moviePlayer setContentURL:url];
}
// 控制选项,slider等
_moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
// 自动播放
_moviePlayer.shouldAutoplay = YES;
// 循环
_moviePlayer.repeatMode = MPMovieRepeatModeOne;
// 全屏
[_moviePlayer setFullscreen:YES animated:YES];
NSString *s = @"http://hot.vrs.sohu.com/ipad1340910.m3u8";
// s = [s stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:s];
if (_moviePlayer == nil) {
_moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
}else {
[_moviePlayer setContentURL:url];
}
// 控制选项,slider等
_moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
// 自动播放
_moviePlayer.shouldAutoplay = YES;
// 循环
_moviePlayer.repeatMode = MPMovieRepeatModeOne;
// 全屏
[_moviePlayer setFullscreen:YES animated:YES];
// 填充模式(跟图片填充模式相似)
内部链接:
图片显示模式(3种)
_moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
[_moviePlayer.view setFrame:self.view.frame];
// 两种都可以:
//[_moviePlayer.view setBackgroundColor:[UIColor clearColor]];
[self.view addSubview:_moviePlayer.view];
[_moviePlayer play];
[self.view addSubview:_moviePlayer.view];
[_moviePlayer play];
}
现在显示:
增加一段代码:
_moviePlayer.view.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
代码:
MPMoviePlayerController有各种设置,拉伸、控制模式、循环模式、自动播放等等,自己看着API文档