AVPlayer stalling on large video files using resource loader delegate

后端 未结 1 1764
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-08 01:08

I am using this approach to save the buffer data of the AVPlayer for video files. Found as the answer in this question Saving buffer data of AVPlayer.

iPhone and iPa

相关标签:
1条回答
  • 2020-12-08 01:46

    when the resource loader delegate fires up the NSURLConnection, the connection takes over saving the NSData to the pending requests and processing them. when the connection finished loading, the resource loader regains responsibility for handling the loading requests. the code was adding the loading request to the pending requests array but the issue was that they were not being processed. changed the method to the following and it works.

    //AVAssetResourceLoader
    - (BOOL)resourceLoader:(AVAssetResourceLoader *)resourceLoader shouldWaitForLoadingOfRequestedResource:(AVAssetResourceLoadingRequest *)loadingRequest
    {
        if(isLoadingComplete == YES)
        {
            //NSLog(@"LOADING WAS COMPLETE");
            [self.pendingRequests addObject:loadingRequest];
            [self processPendingRequests];
            return YES;
        }
    
        if (self.connection == nil)
        {
            NSURL *interceptedURL = [loadingRequest.request URL];
            NSURLComponents *actualURLComponents = [[NSURLComponents alloc] initWithURL:interceptedURL resolvingAgainstBaseURL:NO];
            actualURLComponents.scheme = @"http";
            self.request = [NSURLRequest requestWithURL:[actualURLComponents URL]];
            self.connection = [[NSURLConnection alloc] initWithRequest:self.request delegate:self startImmediately:NO];
            [self.connection setDelegateQueue:[NSOperationQueue mainQueue]];
    
            isLoadingComplete = NO;
            [self.connection start];
        }
    
        [self.pendingRequests addObject:loadingRequest];
        return YES;
    }
    
    0 讨论(0)
提交回复
热议问题