【发布时间】:2016-02-25 08:41:31
【问题描述】:
我正在尝试从远程 URL 播放视频。但它不起作用。我的代码是:
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"start playing");
NSURL *nsURL= [[NSURL alloc]initWithString:@"http://my_server_path:8080/content-service/v1/video/12/RGl1Nm1ib1VLMitFUmM5bEZzYVpxVGllM2RrWUw3Y09yMzdVZ0pzYlEvYjNaYUI5bEQvZERhTUhNTjBOaW5lY1hqYlZSRUM5anAvL3FsUTA2NzEwN2NMM2dnUnkxR0s4QUVyMnV2MlBLMjA9?thumb=false"];
videoPlayer = [[MPMoviePlayerController alloc]
initWithContentURL:nsURL];
[videoPlayer.view setFrame:CGRectMake(0, 0,self.view.frame.size.width, self.view.frame.size.height)];
videoPlayer.controlStyle = MPMovieControlStyleDefault;
videoPlayer.movieSourceType = MPMovieSourceTypeStreaming;//MPMovieSourceTypeFile/MPMovieSourceTypeUnknown ;
[self.view addSubview:videoPlayer.view];
[videoPlayer prepareToPlay];
[videoPlayer play];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:videoPlayer];
videoPlayer.shouldAutoplay = YES;
}
- (void) moviePlayBackDidFinish:(NSNotification*)notification {
NSError *error = [[notification userInfo] objectForKey:@"error"];
if (error) {
NSLog(@"Did finish with error: %@", error);
}
}
我收到了这条消息
完成但出现错误:Error Domain=MediaPlayerErrorDomain 代码=-11850“操作停止”用户信息=0x15e77b20 {NSLocalizedDescription=操作已停止}
当我在浏览器中复制/粘贴我的视频 URL 时,它会成功下载(甚至不是浏览器中的缓冲区),完成下载后它在笔记本电脑中可以正常播放。我很沮丧,请帮忙,任何建议都会很棒,在此先感谢
【问题讨论】:
-
您是否尝试过使用本地服务器以外的 URL?
-
“当我在浏览器中复制/粘贴我的视频 URL 时,它会成功下载(甚至不是浏览器中的缓冲区),完成下载后它在笔记本电脑上可以正常播放” - 这是因为它来自您的计算机,而不是从远程服务器。您的代码看起来不错。
-
它在模拟器上运行吗?
-
让我检查一下,完成后我会与您分享结果。
-
@ Lunatic999,是的,我发现了我的问题:我的 HTTP 服务器不支持字节范围请求。 请务必确保您的 HTTP 服务器支持字节范围请求。有关详细信息,请参阅此链接。 stackoverflow.com/questions/22250368/…
标签: ios objective-c iphone video mpmovieplayercontroller