当前位置: 代码迷 >> Iphone >> 请问MPMoviePlayerViewController相关
  详细解决方案

请问MPMoviePlayerViewController相关

热度:553   发布时间:2016-04-25 06:53:52.0
请教MPMoviePlayerViewController相关
大家好,我按照网络上的帖子写一个用MPMoviePlayerViewController 播放本地与远程视频的例子,碰到不少问题望大虾能帮忙指导:
我是在一个UIViewControl模板中添加两个按钮:一个点击后执行播放本地代码,另一个执行远程视频代码。
1. 播放本地视频:能播放mp4,但不能播放3gp格式(对应的MP4和3gp资源文件我肯定已经加到resource里):现象是执行play后,后面系统马上回调我注册的finishCallback。
2. 播放远程视频:也不能成功,系统马上回调我注册的finishCallback。

我的代码如下(刚开始学习IOS,大虾快帮帮忙啊,:)):
-(IBAction)playUrlVideo //按钮点击后执行此处远程播放代码
{
NSString *url =@"http://www.itc.virginia.edu/network/videotest/when-lg.mov";
isUrl = YES;
[self playerRun:url];
}

-(IBAction)playFileVideo //按钮点击后执行此处本地播放代码
{
NSString *url = [[NSBundle mainBundle] pathForResource:@"cv" ofType:@"mp4"];
isUrl = NO;
[self playerRun:url];
}

-(void)playerRun:(NSString *)url
{
NSURL *urlPath;

if (isUrl) {
urlPath = [[NSURL alloc] initWithString:url];
}
else {
urlPath = [[NSURL alloc] initFileURLWithPath:url];
}

MPMoviePlayerViewController *pc = [[MPMoviePlayerViewController alloc]initWithContentURL:urlPath];
self.player = pc;
[pc release];

//add view.
[self.view addSubview:player.view];

//set animation.
[self presentMoviePlayerViewControllerAnimated:player];

//set config and start playing.
player.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
player.moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
[player.moviePlayer play];

//callback
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];

[urlPath release];
}

-(void)playCallback:(NSNotification *)notification
{
NSError *error = [[notification userInfo] objectForKey:@"error"];
if (error) {
  //这里没有进来
NSLog(@"DidFinishNotification has error %@",error);
}

[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:nil];

if (player) {
[self dismissMoviePlayerViewControllerAnimated];
[player.moviePlayer stop];
player.moviePlayer.initialPlaybackTime=-1.0;
[player release];
player = nil;
}
}


------解决方案--------------------
没有做过
http://developer.apple.com/library/ios/#documentation/MediaPlayer/Reference/MPMoviePlayerController_Class/Reference/Reference.html

看文档吧
------解决方案--------------------
MPMoviePlayerViewController支持视频格式:H.264 视频最高可达 1080p,每秒 30 帧,High Profile level 4.1,采用 AAC-LC 声音格式,最高 160 Kbps,48kHz, 立体声为 .m4v, .mp4 与 .mov 文件格式;
MPEG-4 视频最高可达 2.5 Mbps,640 x 480,每秒 30 帧,Simple Profile 采用 AAC-LC 声音格式,每声道最高 160 Kbps,48 KHz,立体声为 .m4v、.mp4 与 .mov 文件格式;
Motion JPEG (M-JPEG) 最高可达 35 Mbps,1280 x 720,每秒 30 帧,音频为 ulaw 格式,PCM 立体声为 .avi 文件格式

木有3gp呀??
  相关解决方案