Hi,
I'm using AVPlayer and AVAssetResourceLoaderDelegate to handle a custom video playback (streaming) from remote server. In the delegate code, it will uses its own NSURLSession to create a data task retrieving the video from the remote server, and feed the data to AVAssetResourceLoader.
The first loadingRequest I got is good: it's a contentInformationRequest and I do the following: (cotentType will be "video/mp4")
request.contentInformationRequest.byteRangeAccessSupported = true;
request.contentInformationRequest.contentType = response.MIMEType;
request.contentInformationRequest.contentLength = totalLength;
after that I'll get the first data request, however the data request always has "requestsAllDataToEndOfResource" set to true, and requestedLength set to "totalLength", as in this debug output:
data request = requested offset = 0,
requested length = 28875525,
requests all data to end of resource = YES,
current offset = 0>
I was expecting this data request is only asking for a range of data, especially it's the first data request (after the contentInfoRequest). Why is that?
Then my code would continue to handle this as it's getting more data from the remote server asynchronically, it will give it to the data request:
- (void)URLSession:(NSURLSession *)session
dataTask:(NSURLSessionDataTask *)dataTask
didReceiveData:(NSData *)data
{
[self.currentRequest.dataRequest respondWithData:respondData];
However, after the above callback responds to the dataRequest with data for a few time (3 or 4 times), we hit the 2nd issue, the loadingRequest was cancelled:
data request =
requested offset = 0,
requested length = 28875525,
requests all data to end of resource = YES,
current offset = 25284>
We can see that the request currentOffset is moving forward but far from finished. What could trigger the cancel? (The user did not cancel it via AVPlayer UI).
So, we have 2 questions:
1). why the first data request always asks for the whole length of data?
2). what could trigger cancelling the loadingRequest when we are feeding the data to the data request?
Thanks.