【问题标题】:How to config my server to providing the video file play with MPMoviePlayerViewController?如何配置我的服务器以使用 MPMoviePlayerViewController 提供视频文件播放?
【发布时间】:2013-01-14 06:46:36
【问题描述】:

我想使用 MPMoviePlayerViewController 在我的服务器上播放视频文件。但它不起作用。

我的 iOS 代码如下:

NSURL *mediaURL = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:@"http://127.0.0.1:3000/media/%@", @"sample_iTunes.mov"]];
self.player = [[MPMoviePlayerViewController alloc] initWithContentURL: mediaURL];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:self.player.moviePlayer];
self.player.moviePlayer.shouldAutoplay = YES;
self.player.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
[self presentMoviePlayerViewControllerAnimated:self.player];
[self.player.moviePlayer prepareToPlay];
[self.player.moviePlayer play];

-(void)movieFinishedCallback:(NSNotification*)aNotification
{
    NSLog(@"%@",[aNotification valueForKey:@"userInfo"]);
    MPMoviePlayerViewController* theMovie = [aNotification object];
}

我收到来自NSNotification 的错误消息是:

MPMoviePlayerPlaybackDidFinishReasonUserInfoKey = 1;
error = "Error Domain=MediaPlayerErrorDomain Code=-11850 \"Operation Stopped\" UserInfo=0x1d51b640 {NSLocalizedDescription=Operation Stopped}";

然后我把网址改成

http://km.support.apple.com/library/APPLE/APPLECARE_ALLGEOS/HT1211/sample_iTunes.mov

但是效果很好。由于这两个文件是完全相同的文件。我认为我的远程服务器一定有问题。这是来自我的服务器的响应标头:

HTTP/1.1 200 OK
Content-Length: 3284257
Date: Mon, 14 Jan 2013 06:06:12 GMT
Last-Modified: Sun, 13 Jan 2013 10:44:02 +0000
Accept-Ranges: bytes
Content-Type: video/quicktime
Connection: close
Server: Jetty(7.6.1.v20120215)

另外,该视频可以在我的 Macbook 上用 Chrome/Safari 播放,但它也不能在 iPhone 上用浏览器播放。

【问题讨论】:

  • 我也有同样的问题。设法解决了它。请帮忙。

标签: ios ios6 mpmovieplayercontroller


【解决方案1】:

更正内容URL后,如果Error Domain=MediaPlayerErrorDomain Code=-11850 \"Operation Stopped\"错误仍然出现,可能是因为您的HTTP服务器不支持字节范围请求。请参阅MPMoviePlayerPlaybackDidFinishNotification is called immediately 了解更多信息。

【讨论】:

    【解决方案2】:

    您将 MPMoviePlayerController 指向 127.0.0.1,这是当前设备的 IP。因此,您的 iOS 应用正在寻找在您的 iPhone 上 托管该文件的 Web 服务器。您的代码看起来不错,否则您只需将 .mov 托管在有效的地方。

    【讨论】:

      猜你喜欢
      • 2012-06-10
      • 2019-09-24
      • 1970-01-01
      • 1970-01-01
      • 2016-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多