AVFoundation正在加载Google Drive Video

时间:2018-01-10 15:16:40

标签: ios swift macos avfoundation avplayer

任何人都成功设法使用AVFoundation AVPlayer播放Google视频广告?

Objective-c或swift,ios或osx对我来说会很好。

我尝试了什么?

我试过了:

  • iOS Stream video from Google drive Swift。在这里,如果它试图从网址中提取链接,我会拒绝访问(视频是公开的)。

  • 从Google驱动器中提取链接并使用该链接,例如。 video link,但是当我在应用中使用它时,没有任何内容被加载。

  • 在查看其他解决方案的网页和内容之后尝试了类似this的内容,没有运气

链接到video

提前致谢!

1 个答案:

答案 0 :(得分:1)

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.
    }
}

在此sample project中,目标c中有3个自定义AVAssetResourceLoaderDelegate的实现。

基本上,一旦您拥有下载URL以将其架构替换为自定义架构,您将不得不做的事情。像gdrive://而不是https://之类的东西。

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

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