RDG
RDG

Reputation: 131

Unknown error -12881 when using AVAssetResourceLoader

I am trying to write a custom resourceLoader delegate to work with an AVURLAsset. I have started with the AVARLDelegateDemo code from Apple. I am trying to playback an HLS url. I am testing on an iPad.

What I notice is that the playlist file (.m3u8) gets downloaded correctly. Then video file (.ts) also gets downloaded. I know that the .ts file is downloaded because I can see the GET request completing on the web server with status 200. I also set a breakpoint at the following line:

[loadingRequest.dataRequest respondWithData:data];

The length of data matches the file size and the first byte is the sync byte of the .ts (0x47) as expected.

The problem is that the app displays an error code. The following dialog pops up:

"The operation could not be completed. An unknown error occurred (-12881)"

Googling for this error has not turned up any information. I do not know what to check for or how to get more information. It is not as if the app is crashing and giving me a stack trace. The video refuses to play and I get no more information beyond the "unknown error -12881" This is not a lot to go on.

Also, if I point an unmodified version of the demo code at my playlist, the video plays just fine.

Can anyone tell me what is going wrong? Here is the code from my customized resource loader.

- (BOOL) resourceLoader:(AVAssetResourceLoader *)resourceLoader shouldWaitForLoadingOfRequestedResource:(AVAssetResourceLoadingRequest *)loadingRequest

NSURLRequest *redirect = nil;

redirect = [self generateRedirectURL:(NSURLRequest *)[loadingRequest request]];

if (redirect)
{
    NSURLSession *session = [NSURLSession sharedSession];
    [[session dataTaskWithURL:redirect.URL
            completionHandler:^(NSData *data,
                                NSURLResponse *response,
                                NSError *error) {
                [loadingRequest.dataRequest respondWithData:data];
                [loadingRequest finishLoading];

            }] resume];

} else
{
    [self reportError:loadingRequest withErrorCode:badRequestErrorCode];
}
return YES;
}

Upvotes: 2

Views: 2327

Answers (1)

RDG
RDG

Reputation: 131

For the record:

I contacted Apple Developer Tech Support about the issue with trying to use the AVAssetResourceLoaderDelegate to get access to the .ts files. This approach does not work because:

"

It is not possible to have access to the data as it is being downloaded. iOS only allows only the following to be returned via AVAssetResourceLoaderDelegate for HTTP Live Streaming media: - key requests - playlist - media redirects

"

For my use case, I ended up using a local web server (https://github.com/swisspol/GCDWebServer) and sending all requests to a web server within the app. This web server then makes requests to the remote server

Upvotes: 8

Related Questions