ios - MPMoviePlayerController 和基于 Auth 的 HLS 后端服务器

标签 ios mpmovieplayercontroller http-live-streaming

我目前正在使用 MPMoviePlayerController 在我的 iOS 应用程序中提供视频服务。这些文件是从我们需要身份验证的后端服务器流式传输的。它是授权 HTTP header 中基于 key 的身份验证集。

它曾经完美地处理单个视频文件。现在我们正在尝试实现 HLS 自适应流,但我们遇到了障碍。我目前正在使用自定义 NSURLProtocol 子类来捕获对我们的后端服务器发出的请求并注入(inject)正确的 Authorization header 。对于 HLS,它根本不起作用。

当我们查看服务器日志时,我们清楚地看到对 m3u8 文件的第一次请求工作正常。然后所有后续调用(其他 m3u8 文件和 ts 也)被 403 禁止。似乎 MPMoviePlayerController 没有为其他文件使用 NSURLProtocol。 (旁注:它确实适用于模拟器思想,但不适用于物理设备,这让我认为两者的实现方式不同)。

MPMoviePlayerController实例化

self.videoController = [[MPMoviePlayerController alloc] initWithContentURL:video.videoURL];

URL协议(protocol)拦截

+ (NSURLRequest *) canonicalRequestForRequest:(NSURLRequest *)request {
    NSMutableURLRequest *newRequest = request.mutableCopy;
    [newRequest setValue:@"HIDDEN" forHTTPHeaderField:@"Authorization"];
    return newRequest;
}

有什么想法、建议、解决方法吗?

最佳答案

在与 Apple Developer Technical Support 核实后,我认为我想要实现的目标是不可能的(并且不受支持)。

以下是回复中的引述:

The problem you're seeing with NSURLProtocol and so on is that the movie playback subsystem does not run its HTTP requests within your process. Rather, these requests are run from within a separate system process, mediaserverd. Thus, all your efforts to affect the behaviour of that playback are futile.

关于ios - MPMoviePlayerController 和基于 Auth 的 HLS 后端服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35926426/

相关文章:

ios - 当它不是 rootviewcontroller 并且没有导航 Controller 时,如何从 SKScene 访问以前的 View Controller ?

ios - JSON解析数据没有被调用? swift

ios - 动画 CAShapeLayer : Do On Completion

ffmpeg - 我正在使用 ffmpeg 在实时流上叠加图像。我如何根据屏幕的宽度进行缩放以使其完全适合

ios - AVPlayer HLS 直播流 IOS

android - VideoView 为 HLS 过早触发 OnPreparedListener

objective-c - NSUTF8StringEncoding 返回 nil NSString

xcode - currentPlaybackTime 和 NSTimer 在视频期间启动 View ,并在使用 scrubber 定位时间点时正确启动/重新启动

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

ios - 在后台播放 MPMoviePlayerController