Skip to content

Commit

Permalink
Added quality settings for video export.
Browse files Browse the repository at this point in the history
  • Loading branch information
olofd committed Apr 8, 2017
1 parent b597536 commit 080be72
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 8 deletions.
5 changes: 3 additions & 2 deletions example/react-native-camera-roll-picker/camera-roll-picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,10 @@ class CameraRollPicker extends Component {

console.log(RNFetchBlob.fs.dirs);
const dirs = RNFetchBlob.fs.dirs
data.assets[0].saveAssetToDisk({
data.assets[4].saveAssetToDisk({
dir: RNFetchBlob.fs.dirs.DocumentDir,
fileName : "olof.jpg"
deliveryMode : 'mediumQuality',
version : 'current'
}).then((uri) => {
console.log('finnished');
RNFetchBlob.fs.exists(uri)
Expand Down
53 changes: 47 additions & 6 deletions ios/RNPhotosFramework/RNPFManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -376,12 +376,8 @@ - (dispatch_queue_t)methodQueue

PHAsset* asset = [PHAssetsService getAssetsFromArrayOfLocalIdentifiers:@[[RCTConvert NSString:params[@"localIdentifier"]]]].firstObject;

PHVideoRequestOptions *options = [PHVideoRequestOptions new];
options.version = PHVideoRequestOptionsVersionOriginal;
options.networkAccessAllowed = YES;

[[PHImageManager defaultManager] requestAVAssetForVideo:asset
options:options
options:[self getVideoRequestOptionsFromParams:params]
resultHandler:
^(AVAsset * _Nullable avasset,
AVAudioMix * _Nullable audioMix,
Expand All @@ -395,7 +391,7 @@ - (dispatch_queue_t)methodQueue
NSString *fullFileName = [path stringByAppendingPathComponent:[self getFileNameFromParamsObj:params]];
NSURL *fileURL = [NSURL fileURLWithPath:fullFileName];

if ([[NSFileManager defaultManager] isDeletableFileAtPath:fullFileName]) {
if ([[NSFileManager defaultManager] fileExistsAtPath:fullFileName] && [[NSFileManager defaultManager] isDeletableFileAtPath:fullFileName]) {
BOOL success = [[NSFileManager defaultManager] removeItemAtPath:fullFileName error:&error];
if (!success) {
NSLog(@"Error removing file at path: %@", error.localizedDescription);
Expand All @@ -414,7 +410,41 @@ - (dispatch_queue_t)methodQueue
}];

}
}


-(PHVideoRequestOptions *)getVideoRequestOptionsFromParams:(NSDictionary *)params {
PHVideoRequestOptions *videoRequestOptions = [PHVideoRequestOptions new];
videoRequestOptions.networkAccessAllowed = YES;

NSString *deliveryModeQuery = [RCTConvert NSString:params[@"deliveryMode"]];
NSString *versionQuery = [RCTConvert NSString:params[@"version"]];

PHVideoRequestOptionsVersion version = PHVideoRequestOptionsVersionOriginal;

if(versionQuery) {
if([versionQuery isEqualToString:@"current"]) {
version = PHVideoRequestOptionsVersionCurrent;
}
}

PHVideoRequestOptionsDeliveryMode deliveryMode = PHVideoRequestOptionsDeliveryModeAutomatic;
if(deliveryModeQuery != nil) {
if([deliveryModeQuery isEqualToString:@"mediumQuality"]) {
deliveryMode = PHVideoRequestOptionsDeliveryModeMediumQualityFormat;
}
else if([deliveryModeQuery isEqualToString:@"highQuality"]) {
deliveryMode = PHVideoRequestOptionsDeliveryModeHighQualityFormat;
}
else if([deliveryModeQuery isEqualToString:@"fast"]) {
deliveryMode = PHVideoRequestOptionsDeliveryModeFastFormat;
}
}
videoRequestOptions.deliveryMode = deliveryMode;
videoRequestOptions.version = version;


return videoRequestOptions;
}

-(NSString *)getFileNameFromParamsObj:(NSDictionary *)params {
Expand Down Expand Up @@ -674,4 +704,15 @@ -(void)saveVideoAtURL:(NSURL *)url toAlbum:(NSString *)albumLocalIdentifier andC
}];
}

- (NSString *)valueForKey:(NSString *)key
fromQueryItems:(NSArray *)queryItems
{
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name=%@", key];
NSURLQueryItem *queryItem = [[queryItems
filteredArrayUsingPredicate:predicate]
firstObject];
return queryItem.value;
}


@end

0 comments on commit 080be72

Please sign in to comment.