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

Commit

Permalink
Fix indent
Browse files Browse the repository at this point in the history
  • Loading branch information
n1ru4l committed Apr 12, 2018
1 parent 2d3acf2 commit 1a9d192
Showing 1 changed file with 28 additions and 30 deletions.
58 changes: 28 additions & 30 deletions ios/RNThumbnail.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,44 +15,42 @@ - (dispatch_queue_t)methodQueue
RCT_EXPORT_METHOD(get:(NSString *)filepath timestamp:(NSNumber * __nonnull)timestamp resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject)
{
@try {
filepath = [filepath stringByReplacingOccurrencesOfString:@"file://"
@try {
filepath = [filepath stringByReplacingOccurrencesOfString:@"file://"
withString:@""];
NSURL *vidURL = [NSURL fileURLWithPath:filepath];
NSURL *vidURL = [NSURL fileURLWithPath:filepath];

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

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

NSError *err = NULL;
CMTime time = CMTimeMake(value, 60);
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,
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];

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] });
} @catch(NSException *e) {
reject(e.reason, nil, nil);
}
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] });
} @catch(NSException *e) {
reject(e.reason, nil, nil);
}
}

@end


0 comments on commit 1a9d192

Please sign in to comment.