MPMoviePlayer不播放视频。我正在运行iOS 7并在设备和模拟器上获得相同的错误:
2013-10-02 12:49:18.246 xxxx[688:60b] _itemFailedToPlayToEnd: {
kind = 1;
new = 2;
old = 0;
}
我尝试过从互联网和文件系统播放视频,但没有运气。我的代码很简单:
self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:@"http://stream.qtv.apple.com/events/mar/123pibhargjknawdconwecown/12oihbqeorvfhbpiubqnfv3_650_ref.mov"]];
self.moviePlayer.view.frame = self.view.bounds;
self.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
[self.view addSubview:self.moviePlayer.view];
[self.moviePlayer prepareToPlay];
列出的网址是有效的电影: http://stream.qtv.apple.com/events/mar/123pibhargjknawdconwecown/12oihbqeorvfhbpiubqnfv3_650_ref.mov
我也尝试过使用MPMoviePlayerViewController,但这也不起作用。
答案 0 :(得分:2)
MPMovieSourceTypeStreaming
似乎有些错误。在我的应用程序中,我正在从网络上传输视频(与您相同),并且此源类型的问题消失了:
self.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
我知道这很奇怪,因为我们正在播放视频,但这是唯一适用于我的解决方案。
希望有所帮助:)
答案 1 :(得分:0)
试试这个并抱歉迟到的回复:
NSURL *fileURL = [NSURL URLWithString:@"file url from the internet "];
MPMoviePlayerViewController *moviePlayerController = [[MPMoviePlayerViewController alloc] initWithContentURL:fileURL];
[moviePlayerController.moviePlayer setFullscreen:YES animated:YES];
[moviePlayerController.moviePlayer.view setFrame: self.view.bounds];
[moviePlayerController.moviePlayer setControlStyle:MPMovieControlStyleFullscreen];
[moviePlayerController.moviePlayer setMovieSourceType:MPMovieSourceTypeFile];
[self presentMoviePlayerViewControllerAnimated:moviePlayerController];
[moviePlayerController.moviePlayer prepareToPlay];
[moviePlayerController.moviePlayer play];
答案 2 :(得分:0)
1.将mov文件更改为mp4文件,似乎播放器无法支持mov文件
2.删除代码self.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
或改为
self.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
3.之后添加代码[self.moviePlayer setFullscreen:YES];
[self.view addSubview:self.moviePlayer.view];
注意:您必须记下序列,否则您只能听到声音但无法观看电影
如果你想使用MPMoviePlayerViewController,就像这样:
MPMoviePlayerViewController *moviePlayerViewController;
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:@"http://.../movie.mp4"]];//note:mp4 file
[self presentMoviePlayerViewControllerAnimated:moviePlayerViewController];
重要提示:如果网址错误,您也会收到相同的错误。例如:这是错误
moviePlayer=[[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:@"movie.mp4"]];
更正:
如果网址是网址,那么就像这样:
moviePlayer=[[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:@"http://..../movie.mp4"]];
否则,如果文件是本地文件,则像这样:
moviePlayer=[[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"movie" ofType:@"mp4”]]];