From 004b66dcbcd9f312a988ef3a9f16254db933a70a Mon Sep 17 00:00:00 2001 From: Laurin Quast Date: Thu, 2 Aug 2018 19:23:26 +0200 Subject: [PATCH] add delegate method for exposing the mime type of the file --- .../Classes/DVAssetLoaderDelegate.m | 15 +++++++++++---- .../Classes/DVAssetLoaderDelegatesDelegate.h | 10 ++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/DVAssetLoaderDelegate/Classes/DVAssetLoaderDelegate.m b/DVAssetLoaderDelegate/Classes/DVAssetLoaderDelegate.m index 6e7969c..de6af40 100644 --- a/DVAssetLoaderDelegate/Classes/DVAssetLoaderDelegate.m +++ b/DVAssetLoaderDelegate/Classes/DVAssetLoaderDelegate.m @@ -317,7 +317,9 @@ - (void)URLSession:(NSURLSession *)session task:(NSURLSessionDataTask *)task did long long requestedOffset = loadingRequest.dataRequest.requestedOffset; NSUInteger length = loadedData.length; long long fullLength = [[(NSHTTPURLResponse *)task.response allHeaderFields][@"Content-Range"] componentsSeparatedByString:@"/"].lastObject.longLongValue; - [self processData:loadedData forOffset:requestedOffset length:length fullLength:fullLength]; + NSString *mimeType = [(NSHTTPURLResponse *)task.response allHeaderFields][@"Content-Type"]; + + [self processData:loadedData forOffset:requestedOffset length:length fullLength:fullLength mimeType:mimeType]; [self.pendingRequests removeObjectAtIndex:index]; [self.datas removeObjectAtIndex:index]; @@ -360,7 +362,7 @@ - (void)fillInContentInformation:(AVAssetResourceLoadingContentInformationReques } } -- (void)processData:(NSData *)data forOffset:(long long)offset length:(NSUInteger)length fullLength:(long long)fullLength { +- (void)processData:(NSData *)data forOffset:(long long)offset length:(NSUInteger)length fullLength:(long long)fullLength mimeType:(NSString *)mimeType { if (fullLength == 0 || data.length == 0) { return; } @@ -374,8 +376,13 @@ - (void)processData:(NSData *)data forOffset:(long long)offset length:(NSUIntege } NSData *dataToSave = concatedDataFromRanges(self.datasForSavingToCache, fullLength); - if (dataToSave && [self.delegate respondsToSelector:@selector(dvAssetLoaderDelegate:didLoadData:forURL:)]) { - [self.delegate dvAssetLoaderDelegate:self didLoadData:dataToSave forURL:self.originalURL]; + if (dataToSave) { + if ([self.delegate respondsToSelector:@selector(dvAssetLoaderDelegate:didLoadData:forURL:)]) { + [self.delegate dvAssetLoaderDelegate:self didLoadData:dataToSave forURL:self.originalURL]; + } + if ([self.delegate respondsToSelector:@selector(dvAssetLoaderDelegate:didLoadData:forURL:withMIMEType:)]) { + [self.delegate dvAssetLoaderDelegate:self didLoadData:dataToSave forURL:self.originalURL withMIMEType:mimeType]; + } } } diff --git a/DVAssetLoaderDelegate/Classes/DVAssetLoaderDelegatesDelegate.h b/DVAssetLoaderDelegate/Classes/DVAssetLoaderDelegatesDelegate.h index b21fe80..2f87acc 100644 --- a/DVAssetLoaderDelegate/Classes/DVAssetLoaderDelegatesDelegate.h +++ b/DVAssetLoaderDelegate/Classes/DVAssetLoaderDelegatesDelegate.h @@ -18,6 +18,16 @@ - (void)dvAssetLoaderDelegate:(DVAssetLoaderDelegate *)loaderDelegate didLoadData:(NSData *)data forURL:(NSURL *)url; + +/** + Called when the file downloaded completely. + May not be called when the file contains information not relevant to playback. + */ +- (void)dvAssetLoaderDelegate:(DVAssetLoaderDelegate *)loaderDelegate + didLoadData:(NSData *)data + forURL:(NSURL *)url + withMIMEType:(NSString*)mimeType; + /** Called when loader delegate downloaded data range so you can manually operate with a cache. */