我正在使用AVAssetResourceLoader加载数据并使用AVPlayerViewController进行播放。 它在iOS10、11下正常工作,但在iOS12下不再工作。 播放时,进度条会向前移动,但是视频只能播放1秒,并且一直停留到结束。
这是我的AVAssetResourceLoader代码:
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
}
}