如何配置我的服务器以提供与MPMoviePlayerViewController一起播放的视频文件? [英] How to config my server to providing the video file play with MPMoviePlayerViewController?

查看:86
本文介绍了如何配置我的服务器以提供与MPMoviePlayerViewController一起播放的视频文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to using MPMoviePlayerViewController to play the video file on my server. But It not works.

我的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

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

But it works well. Since the two files are exactly the same file. I think there must be something wrong with my remote server. And here is the response headers from my server :

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上播放。

In additional, The video can play on my macbook with Chrome/Safari, But it can't play on iPhone with browsers too.

推荐答案

更正内容网址后,如果错误域= MediaPlayerErrorDomain Code = -11850 \Operation Stopped \错误仍然会发生,则可能是因为您的HTTP服务器不支持字节范围请求。有关详细信息,请参阅立即调用MPMoviePlayerPlaybackDidFinishNotification

After correcting the content URL, if the Error Domain=MediaPlayerErrorDomain Code=-11850 \"Operation Stopped\" error still happens, it may be because your HTTP server does not support byte-range requests. See MPMoviePlayerPlaybackDidFinishNotification is called immediately for more information.

这篇关于如何配置我的服务器以提供与MPMoviePlayerViewController一起播放的视频文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆