Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add delegate method for exposing the mime type of the file #5

Merged
merged 1 commit into from
Sep 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions DVAssetLoaderDelegate/Classes/DVAssetLoaderDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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;
}
Expand All @@ -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];
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions DVAssetLoaderDelegate/Classes/DVAssetLoaderDelegatesDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down