AVFoundation加载谷歌云端硬盘视频



>有人成功地用AVFoundation,AVPlayer播放Google云端硬盘视频吗?

Objective-c或swift,ios或osx对我来说可以正常工作。

我试过什么?

我试过了:

  • 来自谷歌驱动器的iOS流视频 斯威夫特 .在这里,如果它尝试从 url 中提取链接,我的访问被拒绝(视频是公开的(。

  • 从谷歌驱动器中提取链接并使用该链接,例如视频链接,但是当我在应用程序中使用它时,什么都没有加载。

  • 在研究了网络和其他解决方案后尝试了这样的事情,但没有运气

链接到视频

提前感谢!

Gdrive 不支持视频流,但它支持下载时的简历。

您需要使用具有有效视频网址的自定义AVAssetResourceLoaderDelegate

class GDriveLoader: NSObject, AVAssetResourceLoaderDelegate {
    public func resourceLoader(_ resourceLoader: AVAssetResourceLoader, shouldWaitForLoadingOfRequestedResource loadingRequest: AVAssetResourceLoadingRequest) -> Bool {
        //Here you will put your code to download the bytes requested by AVPlayer. 
        //You can find this info in the loadingRequest.dataRequest.
    }
}

在此示例项目中,目标 c 中有 3 个自定义AVAssetResourceLoaderDelegate实现。

基本上,一旦您拥有下载网址 si 将其架构替换为自定义架构,您将必须做什么。 像gdrive://而不是https://

.

使用此 URL 创建 AVURLAsset 时,您可以访问新创建对象的属性resourceLoader并调用方法 setDelegate 传递您的GDriveLoader

使用自定义架构,AVFoundation 不知道如何获取视频数据,并且会询问资产的资源加载器该怎么做。对于 AVPlayer 当前读取的每个数据块,将多次查询方法resourceLoader(_ resourceLoader: AVAssetResourceLoader, shouldWaitForLoadingOfRequestedResource loadingRequest: AVAssetResourceLoadingRequest)

最新更新