Component is introduced

1. Block the playback data request

    1. From the HTTP url – > sreaming
url = [url streamingURL];
Copy the code
  • The URL changes back to HTTP when downloading
NSURL *url = loadingRequest.request.URL;
Copy the code
    1. Set the agent
    self.resourceLoaderDelegate = [XMGRemoteResourceLoaderDelegate new];
    [asset.resourceLoader setDelegate:self.resourceLoaderDelegate queue:dispatch_get_main_queue()];
Copy the code
  • 3. Proxy response

The registered agent

<AVAssetResourceLoaderDelegate>
Copy the code
- (BOOL)resourceLoader:(AVAssetResourceLoader *)resourceLoader shouldWaitForLoadingOfRequestedResource:(AVAssetResourceLoadingRequest *)loadingRequest {
    NSLog(@"%@", loadingRequest);
    
- (void)resourceLoader:(AVAssetResourceLoader *)resourceLoader didCancelLoadingRequest:(AVAssetResourceLoadingRequest *)loadingRequest;    
Copy the code
  • The player takes two steps
    • Fill in header information

      • loadingRequest.contentInformationRequest.contentLength = totalSize;
      • loadingRequest.contentInformationRequest.contentType = contentType;
      • loadingRequest.contentInformationRequest.byteRangeAccessSupported = YES;
    • Returns response population data

      • [loadingRequest.dataRequest respondWithData:subData];
    • Complete the request

      • [loadingRequest finishLoading];

2. Data processing

    1. Check whether the local cache exists, and if so, return the corresponding amount information directly from the local cache
      1. Obtain the corresponding mimeType based on the file name extension
      1. Gets the total size of the file
      1. Get the data and respond
      1. Complete the request
    1. Otherwise, download the file
      1. Determine if it is downloading. If not, download and return
      1. If yes, determine whether to download it again. If yes, download it again and return
      1. Otherwise, the request stored in the array is processed
      • And during the download process, all requests are processed with constant judgment (via proxy callbacks)
      • Process all requests
          1. For each request, fill in the header information
          1. Calculate fill area
          1. According to the interval of each request, the data is populated
          1. Determine if it can be filled completely, and if so, terminate the request after returning data

3. Obtain the mimeType based on the file name

  • The framework

#import <MobileCoreServices/MobileCoreServices.h>

  • function
CFStringRef contentTypeCF = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef _Nonnull)(fileExtension), NULL);
Copy the code

4.demo

  • Write all the exercises and upload them