Component is introduced
1. Block the playback data request
-
- 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
-
- 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
-
- Check whether the local cache exists, and if so, return the corresponding amount information directly from the local cache
-
- Obtain the corresponding mimeType based on the file name extension
-
- Gets the total size of the file
-
- Get the data and respond
-
- Complete the request
-
- Otherwise, download the file
-
- Determine if it is downloading. If not, download and return
-
- If yes, determine whether to download it again. If yes, download it again and return
-
- 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
-
- For each request, fill in the header information
-
- Calculate fill area
-
- According to the interval of each request, the data is populated
-
- 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