gpt4 book ai didi

iOS-MPMoviePlayerController 无法从远程 URL 播放视频

转载 作者:可可西里 更新时间:2023-11-01 05:51:01 25 4
gpt4 key购买 nike

我正在尝试从远程 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

Source From Byte-Range Request

Solution

关于iOS-MPMoviePlayerController 无法从远程 URL 播放视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35622246/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com