Gdrive does not support the streaming of videos, but it supports the resume on download.
You will need to use a custom AVAssetResourceLoaderDelegate
with a valid video URL.
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.
}
}
In this sample project there are 3 implementations of custom AVAssetResourceLoaderDelegate
in objective c.
Basically what you will have to do once you have the download url si to replace its schema to a custom schema. something like gdrive://
instead of https://
.
when you create your AVURLAsset with this url you can access to the newly created object's property resourceLoader
and call the method setDelegate passing your GDriveLoader
.
With a custom schema AVFoundation doesn't know how to fetch the video data, and will ask to the asset's resource loader what to do. The method resourceLoader(_ resourceLoader: AVAssetResourceLoader, shouldWaitForLoadingOfRequestedResource loadingRequest: AVAssetResourceLoadingRequest)
will be queried multiple times for each chunk of data currently in read by AVPlayer.