我正在尝试从远程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);
}
}
我收到了这条消息
Did finish with error: Error Domain=MediaPlayerErrorDomain
Code=-11850 “Operation Stopped” UserInfo=0x15e77b20
{NSLocalizedDescription=Operation Stopped}
当我在浏览器中复制/粘贴我的视频URL时,它会成功下载(甚至不是浏览器中的缓冲区),完成下载后,它在笔记本电脑中播放得很好.我很沮丧,请帮助,任何建议都会很棒,谢谢你提前
最佳答案 如果视频未在设备上播放,则HTTP服务器不支持字节范围请求.
HTTP servers hosting media files for iOS must support byte-range
requests, which iOS uses to perform random access in media playback.
(Byte-range support is also known as content-range or partial-range
support.) Most, but not all, HTTP 1.1 servers already support
byte-range requests.
Source From Safari Web Service Content