8

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];

列出的 URL 是一部有效的电影: http ://stream.qtv.apple.com/events/mar/123pibhargjknawdconwecown/12oihbqeorvfhbpiubqnfv3_650_ref.mov

我也尝试过使用 MPMoviePlayerViewController,但这也没有用。

4

3 回答 3

3

MPMovieSourceTypeStreaming seems to be buggy on iOS 7. On my app, I'm streaming a video from the web (same as you), and the problem disappear with this source type :

self.moviePlayer.movieSourceType = MPMovieSourceTypeFile;

I know it's strange because we're streaming the video, but this is the only solution that works for me.

Hope it helps :)

于 2013-11-26T12:27:42.947 回答
1

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];

重要提示:如果 URL 错误,您也会收到相同的错误。例如:这是错误的

moviePlayer=[[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:@"movie.mp4"]];

纠正

如果 URL 是 Web URL,则如下所示:

moviePlayer=[[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:@"http://..../movie.mp4"]];

否则,如果文件是本地文件,则如下所示:

moviePlayer=[[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"movie" ofType:@"mp4”]]];
于 2014-04-02T01:04:35.787 回答
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];
于 2013-11-12T12:43:03.690 回答