MPMoviePlayerController没有响应

时间:2012-03-15 03:32:46

标签: iphone objective-c cocoa-touch

MPMoviePlayerController *player 
    = [[MPMoviePlayerController alloc] initWithContentURL:video_url];

[[player view] setFrame : [ib_image_base_view bounds]];

[ib_image_base_view addSubview : [player view]];

[player play];

以上是我用来播放视频文件的5个陈述。 video_url有价值: “Intro_00.mp4 - file:// localhost /”由NSLog语句回显。其值初始化为:video_url = [NSURL fileURLWithPath:@“Intro_00.mp4”];

问题是MoviePlayer没有任何响应,Xcode也没有错误或警告消息。 5行代码是iPhone项目的一部分。

希望有人可以提供一些提示。

(***由于某些原因,stackoverflow的“添加评论”目前不起作用)

评论在下面添加......

按照建议尝试了以下操作,但仍无响应。

[player setControlStyle: MPMovieControlStyleEmbedded];

更新1:

一直发现video_url一直是“null”。所以我从Apple找到并下载了一个相关的示例项目。但同样的问题似乎仍然存在。有关详细信息,请参阅here

更新2:

@Eduardo找到了这两个问题的解决方案。所以这个问题应该关闭。感谢所有看过我帖子的人的帮助和回复:)

5 个答案:

答案 0 :(得分:1)

这里有一个示例代码....它对你有帮助.....

Download Movie Player Source Code

答案 1 :(得分:1)

使用[[NSBundle mainBundle] pathForResource:"Intro_00.mp4"]并记住将文件添加到包中(项目构建步骤>复制资源)

答案 2 :(得分:0)

尝试添加:

[player setControlStyle: MPMovieControlStyleEmbedded];

希望这有帮助。

答案 3 :(得分:0)

试试这段代码,

播放视频之前必须包含MediaPlayer.framework和导入头文件

MPMoviePlayerController *moviePlayer=[[MPMoviePlayerController alloc]initWithContentURL:videoURL];

moviePlayer.view.frame = CGRectMake(0,0,1024,768);

[self.view addSubview:moviePlayer.view];

[moviePlayer play];

答案 4 :(得分:0)

在调用[moviePlayer prepareToPlay]之前,请尝试添加play