@@ -15,44 +15,42 @@ - (dispatch_queue_t)methodQueue
15
15
RCT_EXPORT_METHOD(get:(NSString *)filepath timestamp:(NSNumber * __nonnull)timestamp resolve:(RCTPromiseResolveBlock)resolve
16
16
reject:(RCTPromiseRejectBlock)reject)
17
17
{
18
- @try {
19
- filepath = [filepath stringByReplacingOccurrencesOfString: @" file://"
18
+ @try {
19
+ filepath = [filepath stringByReplacingOccurrencesOfString: @" file://"
20
20
withString: @" " ];
21
- NSURL *vidURL = [NSURL fileURLWithPath: filepath];
21
+ NSURL *vidURL = [NSURL fileURLWithPath: filepath];
22
22
23
- AVURLAsset *asset = [[AVURLAsset alloc ] initWithURL: vidURL options: nil ];
24
- int64_t value = 0 ;
25
- if (timestamp != 0 ) {
26
- AVAssetTrack * videoAssetTrack = [asset tracksWithMediaType: AVMediaTypeVideo].firstObject ;
27
- value = [timestamp longLongValue ] * videoAssetTrack.nominalFrameRate ;
28
- }
23
+ AVURLAsset *asset = [[AVURLAsset alloc ] initWithURL: vidURL options: nil ];
24
+ int64_t value = 0 ;
25
+ if (timestamp != 0 ) {
26
+ AVAssetTrack * videoAssetTrack = [asset tracksWithMediaType: AVMediaTypeVideo].firstObject ;
27
+ value = [timestamp longLongValue ] * videoAssetTrack.nominalFrameRate ;
28
+ }
29
29
30
- AVAssetImageGenerator *generator = [[AVAssetImageGenerator alloc ] initWithAsset: asset];
31
- generator.appliesPreferredTrackTransform = YES ;
30
+ AVAssetImageGenerator *generator = [[AVAssetImageGenerator alloc ] initWithAsset: asset];
31
+ generator.appliesPreferredTrackTransform = YES ;
32
32
33
- NSError *err = NULL ;
34
- CMTime time = CMTimeMake (value, 60 );
33
+ NSError *err = NULL ;
34
+ CMTime time = CMTimeMake (value, 60 );
35
35
36
- CGImageRef imgRef = [generator copyCGImageAtTime: time actualTime: NULL error: &err];
37
- UIImage *thumbnail = [UIImage imageWithCGImage: imgRef];
38
- // save to temp directory
39
- NSString * tempDirectory = [NSSearchPathForDirectoriesInDomains (NSCachesDirectory,
36
+ CGImageRef imgRef = [generator copyCGImageAtTime: time actualTime: NULL error: &err];
37
+ UIImage *thumbnail = [UIImage imageWithCGImage: imgRef];
38
+ // save to temp directory
39
+ NSString * tempDirectory = [NSSearchPathForDirectoriesInDomains (NSCachesDirectory,
40
40
NSUserDomainMask,
41
41
YES ) lastObject ];
42
42
43
- NSData *data = UIImageJPEGRepresentation (thumbnail, 1.0 );
44
- NSFileManager *fileManager = [NSFileManager defaultManager ];
45
- NSString *fullPath = [tempDirectory stringByAppendingPathComponent: [NSString stringWithFormat: @" thumb-%@ .jpg" , [[NSProcessInfo processInfo ] globallyUniqueString ]]];
46
- [fileManager createFileAtPath: fullPath contents: data attributes: nil ];
47
- if (resolve)
48
- resolve (@{ @" path" : fullPath,
49
- @" width" : [NSNumber numberWithFloat: thumbnail.size.width],
50
- @" height" : [NSNumber numberWithFloat: thumbnail.size.height] });
51
- } @catch (NSException *e) {
52
- reject (e.reason , nil , nil );
53
- }
43
+ NSData *data = UIImageJPEGRepresentation (thumbnail, 1.0 );
44
+ NSFileManager *fileManager = [NSFileManager defaultManager ];
45
+ NSString *fullPath = [tempDirectory stringByAppendingPathComponent: [NSString stringWithFormat: @" thumb-%@ .jpg" , [[NSProcessInfo processInfo ] globallyUniqueString ]]];
46
+ [fileManager createFileAtPath: fullPath contents: data attributes: nil ];
47
+ if (resolve)
48
+ resolve (@{ @" path" : fullPath,
49
+ @" width" : [NSNumber numberWithFloat: thumbnail.size.width],
50
+ @" height" : [NSNumber numberWithFloat: thumbnail.size.height] });
51
+ } @catch (NSException *e) {
52
+ reject (e.reason , nil , nil );
53
+ }
54
54
}
55
55
56
56
@end
57
-
58
-
0 commit comments