I'm using AVAssetResourceLoader to load data and AVPlayerViewController to play. It works properly under iOS10, 11 but not work any more under iOS12. When playing, the process bar is moving forward, but the video only plays 1 sec, and stuck till end.
Here's my AVAssetResourceLoader code:
class MediaResourceLoader: NSObject, AVAssetResourceLoaderDelegate {
func resourceLoader(
_ resourceLoader: AVAssetResourceLoader,
shouldWaitForLoadingOfRequestedResource loadingRequest: AVAssetResourceLoadingRequest
) -> Bool {
loadingRequest.contentInformationRequest?.contentType = kUTTypeMPEG4 as String
loadingRequest.contentInformationRequest?.contentLength = Int64(self.data.count)
loadingRequest.contentInformationRequest?.isByteRangeAccessSupported = true
guard let request = loadingRequest.dataRequest else { return false }
if request.requestsAllDataToEndOfResource {
request.respond(with: data)
} else if Int(request.requestedOffset) <= request.requestedLength {
let subData = self.data.subdata(in: Int(request.requestedOffset)..<request.requestedLength)
request.respond(with: subData)
}
loadingRequest.finishLoading()
return true
}
}