Skip to content
This repository has been archived by the owner on Dec 2, 2019. It is now read-only.

Commit

Permalink
More indentation fixes...
Browse files Browse the repository at this point in the history
  • Loading branch information
n1ru4l committed Apr 12, 2018
1 parent 1a9d192 commit 961bf0f
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions ios/RNThumbnail.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,42 +12,44 @@ - (dispatch_queue_t)methodQueue
}
RCT_EXPORT_MODULE()

RCT_EXPORT_METHOD(get:(NSString *)filepath timestamp:(NSNumber * __nonnull)timestamp resolve:(RCTPromiseResolveBlock)resolve
RCT_EXPORT_METHOD(get:(NSString *)filepath
timestamp:(NSNumber * __nonnull)timestamp
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject)
{
@try {
filepath = [filepath stringByReplacingOccurrencesOfString:@"file://"
withString:@""];
withString:@""];
NSURL *vidURL = [NSURL fileURLWithPath:filepath];

AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:vidURL options:nil];
int64_t value = 0;
int64_t value = 1;
if (timestamp != 0) {
AVAssetTrack * videoAssetTrack = [asset tracksWithMediaType: AVMediaTypeVideo].firstObject;
value = [timestamp longLongValue] * videoAssetTrack.nominalFrameRate;
}

AVAssetImageGenerator *generator = [[AVAssetImageGenerator alloc] initWithAsset:asset];
generator.appliesPreferredTrackTransform = YES;

NSError *err = NULL;
CMTime time = CMTimeMake(value, 60);

CGImageRef imgRef = [generator copyCGImageAtTime:time actualTime:NULL error:&err];
UIImage *thumbnail = [UIImage imageWithCGImage:imgRef];
// save to temp directory
NSString* tempDirectory = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory,
NSUserDomainMask,
YES) lastObject];

NSUserDomainMask,
YES) lastObject];
NSData *data = UIImageJPEGRepresentation(thumbnail, 1.0);
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *fullPath = [tempDirectory stringByAppendingPathComponent: [NSString stringWithFormat:@"thumb-%@.jpg", [[NSProcessInfo processInfo] globallyUniqueString]]];
[fileManager createFileAtPath:fullPath contents:data attributes:nil];
if (resolve)
resolve(@{ @"path" : fullPath,
@"width" : [NSNumber numberWithFloat: thumbnail.size.width],
@"height" : [NSNumber numberWithFloat: thumbnail.size.height] });
resolve(@{ @"path" : fullPath,
@"width" : [NSNumber numberWithFloat: thumbnail.size.width],
@"height" : [NSNumber numberWithFloat: thumbnail.size.height] });
} @catch(NSException *e) {
reject(e.reason, nil, nil);
}
Expand Down

0 comments on commit 961bf0f

Please sign in to comment.