react-native-compressor 1.6.4 → 1.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +41 -27
- package/android/build.gradle +95 -42
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +0 -1
- package/android/src/main/AndroidManifestNew.xml +2 -0
- package/android/src/main/java/com/reactnativecompressor/CompressorModule.java +107 -43
- package/android/src/main/java/com/reactnativecompressor/CompressorPackage.java +47 -19
- package/android/src/main/java/com/reactnativecompressor/Image/ImageCompressor.java +28 -16
- package/android/src/main/java/com/reactnativecompressor/Image/utils/ImageCompressorOptions.java +5 -1
- package/android/src/main/java/com/reactnativecompressor/Utils/MediaCache.java +65 -0
- package/android/src/main/java/com/reactnativecompressor/Utils/Utils.java +162 -3
- package/android/src/main/java/com/reactnativecompressor/Video/VideoCompressorHelper.java +7 -4
- package/android/src/main/java/com/reactnativecompressor/Video/VideoModule.java +11 -22
- package/android/src/newarch/CompressorSpec.java +9 -0
- package/android/src/newarch/VideoCompressorSpec.java +9 -0
- package/android/src/oldarch/CompressorSpec.java +34 -0
- package/android/src/oldarch/VideoCompressorSpec.java +26 -0
- package/ios/Compressor-Bridging-Header.h +1 -0
- package/ios/Compressor.h +9 -1
- package/ios/Compressor.mm +427 -0
- package/ios/Compressor.xcodeproj/project.pbxproj +6 -36
- package/ios/Image/ImageCompressor.h +12 -7
- package/ios/Image/ImageCompressor.m +164 -67
- package/ios/Image/ImageCompressorOptions.h +1 -0
- package/ios/Image/ImageCompressorOptions.m +5 -1
- package/ios/Utils/Downloader.h +16 -0
- package/ios/Utils/Downloader.m +150 -0
- package/ios/Utils/MediaCache.h +11 -0
- package/ios/Utils/MediaCache.m +51 -0
- package/ios/Video/VideoCompressor.swift +14 -5
- package/lib/commonjs/Audio/index.js +13 -14
- package/lib/commonjs/Audio/index.js.map +1 -1
- package/lib/commonjs/Image/index.js +26 -7
- package/lib/commonjs/Image/index.js.map +1 -1
- package/lib/commonjs/Main.js +29 -0
- package/lib/commonjs/Main.js.map +1 -0
- package/lib/commonjs/Spec/NativeCompressor.js +10 -0
- package/lib/commonjs/Spec/NativeCompressor.js.map +1 -0
- package/lib/commonjs/Spec/NativeVideoCompressor.js +10 -0
- package/lib/commonjs/Spec/NativeVideoCompressor.js.map +1 -0
- package/lib/commonjs/Video/index.js +17 -25
- package/lib/commonjs/Video/index.js.map +1 -1
- package/lib/commonjs/expo-plugin/compressor.js +1 -4
- package/lib/commonjs/expo-plugin/compressor.js.map +1 -1
- package/lib/commonjs/index.js +21 -28
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/utils/index.js +32 -51
- package/lib/commonjs/utils/index.js.map +1 -1
- package/lib/module/Audio/index.js +13 -11
- package/lib/module/Audio/index.js.map +1 -1
- package/lib/module/Image/index.js +27 -6
- package/lib/module/Image/index.js.map +1 -1
- package/lib/module/Main.js +22 -0
- package/lib/module/Main.js.map +1 -0
- package/lib/module/Spec/NativeCompressor.js +3 -0
- package/lib/module/Spec/NativeCompressor.js.map +1 -0
- package/lib/module/Spec/NativeVideoCompressor.js +3 -0
- package/lib/module/Spec/NativeVideoCompressor.js.map +1 -0
- package/lib/module/Video/index.js +18 -19
- package/lib/module/Video/index.js.map +1 -1
- package/lib/module/expo-plugin/compressor.js +1 -3
- package/lib/module/expo-plugin/compressor.js.map +1 -1
- package/lib/module/index.js +8 -5
- package/lib/module/index.js.map +1 -1
- package/lib/module/utils/index.js +26 -34
- package/lib/module/utils/index.js.map +1 -1
- package/lib/typescript/Audio/index.d.ts +2 -1
- package/lib/typescript/Audio/index.d.ts.map +1 -0
- package/lib/typescript/Image/index.d.ts +11 -6
- package/lib/typescript/Image/index.d.ts.map +1 -0
- package/lib/typescript/Main.d.ts +4 -0
- package/lib/typescript/Main.d.ts.map +1 -0
- package/lib/typescript/Spec/NativeCompressor.d.ts +14 -0
- package/lib/typescript/Spec/NativeCompressor.d.ts.map +1 -0
- package/lib/typescript/Spec/NativeVideoCompressor.d.ts +13 -0
- package/lib/typescript/Spec/NativeVideoCompressor.d.ts.map +1 -0
- package/lib/typescript/Video/index.d.ts +5 -3
- package/lib/typescript/Video/index.d.ts.map +1 -0
- package/lib/typescript/expo-plugin/compressor.d.ts +2 -3
- package/lib/typescript/expo-plugin/compressor.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +7 -3
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/utils/index.d.ts +6 -4
- package/lib/typescript/utils/index.d.ts.map +1 -0
- package/package.json +62 -38
- package/react-native-compressor.podspec +24 -1
- package/src/Audio/index.tsx +6 -4
- package/src/Image/index.tsx +38 -5
- package/src/Main.tsx +41 -0
- package/src/Spec/NativeCompressor.ts +15 -0
- package/src/Spec/NativeVideoCompressor.ts +14 -0
- package/src/Video/index.tsx +28 -11
- package/src/expo-plugin/compressor.ts +2 -1
- package/src/index.tsx +7 -2
- package/src/utils/index.tsx +11 -5
- package/android/.gradle/6.9/executionHistory/executionHistory.lock +0 -0
- package/android/.gradle/6.9/fileChanges/last-build.bin +0 -0
- package/android/.gradle/6.9/fileHashes/fileHashes.bin +0 -0
- package/android/.gradle/6.9/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/6.9/gc.properties +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +0 -2
- package/android/.gradle/checksums/checksums.lock +0 -0
- package/android/.gradle/checksums/md5-checksums.bin +0 -0
- package/android/.gradle/checksums/sha1-checksums.bin +0 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/android/.idea/caches/build_file_checksums.ser +0 -0
- package/android/.idea/compiler.xml +0 -6
- package/android/.idea/gradle.xml +0 -20
- package/android/.idea/jarRepositories.xml +0 -45
- package/android/.idea/libraries/Gradle__androidx_annotation_annotation_1_1_0.xml +0 -13
- package/android/.idea/libraries/Gradle__androidx_appcompat_appcompat_1_0_2_aar.xml +0 -24
- package/android/.idea/libraries/Gradle__androidx_arch_core_core_common_2_0_0.xml +0 -11
- package/android/.idea/libraries/Gradle__androidx_arch_core_core_runtime_2_0_0_aar.xml +0 -19
- package/android/.idea/libraries/Gradle__androidx_asynclayoutinflater_asynclayoutinflater_1_0_0_aar.xml +0 -19
- package/android/.idea/libraries/Gradle__androidx_autofill_autofill_1_1_0_aar.xml +0 -16
- package/android/.idea/libraries/Gradle__androidx_collection_collection_1_0_0.xml +0 -11
- package/android/.idea/libraries/Gradle__androidx_coordinatorlayout_coordinatorlayout_1_0_0_aar.xml +0 -24
- package/android/.idea/libraries/Gradle__androidx_core_core_1_1_0_aar.xml +0 -16
- package/android/.idea/libraries/Gradle__androidx_cursoradapter_cursoradapter_1_0_0_aar.xml +0 -19
- package/android/.idea/libraries/Gradle__androidx_customview_customview_1_0_0_aar.xml +0 -19
- package/android/.idea/libraries/Gradle__androidx_documentfile_documentfile_1_0_0_aar.xml +0 -19
- package/android/.idea/libraries/Gradle__androidx_drawerlayout_drawerlayout_1_0_0_aar.xml +0 -24
- package/android/.idea/libraries/Gradle__androidx_fragment_fragment_1_0_0_aar.xml +0 -24
- package/android/.idea/libraries/Gradle__androidx_interpolator_interpolator_1_0_0_aar.xml +0 -19
- package/android/.idea/libraries/Gradle__androidx_legacy_legacy_support_core_ui_1_0_0_aar.xml +0 -19
- package/android/.idea/libraries/Gradle__androidx_legacy_legacy_support_core_utils_1_0_0_aar.xml +0 -19
- package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_common_2_0_0.xml +0 -11
- package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_livedata_2_0_0_aar.xml +0 -19
- package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_livedata_core_2_0_0_aar.xml +0 -19
- package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_runtime_2_0_0_aar.xml +0 -19
- package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_viewmodel_2_0_0_aar.xml +0 -19
- package/android/.idea/libraries/Gradle__androidx_loader_loader_1_0_0_aar.xml +0 -19
- package/android/.idea/libraries/Gradle__androidx_localbroadcastmanager_localbroadcastmanager_1_0_0_aar.xml +0 -19
- package/android/.idea/libraries/Gradle__androidx_print_print_1_0_0_aar.xml +0 -24
- package/android/.idea/libraries/Gradle__androidx_slidingpanelayout_slidingpanelayout_1_0_0_aar.xml +0 -19
- package/android/.idea/libraries/Gradle__androidx_swiperefreshlayout_swiperefreshlayout_1_0_0_aar.xml +0 -24
- package/android/.idea/libraries/Gradle__androidx_vectordrawable_vectordrawable_1_0_1_aar.xml +0 -19
- package/android/.idea/libraries/Gradle__androidx_vectordrawable_vectordrawable_animated_1_0_0_aar.xml +0 -19
- package/android/.idea/libraries/Gradle__androidx_versionedparcelable_versionedparcelable_1_1_0_aar.xml +0 -13
- package/android/.idea/libraries/Gradle__androidx_viewpager_viewpager_1_0_0_aar.xml +0 -19
- package/android/.idea/libraries/Gradle__com_facebook_fbjni_fbjni_java_only_0_2_2.xml +0 -13
- package/android/.idea/libraries/Gradle__com_facebook_fresco_drawee_2_5_0_aar.xml +0 -15
- package/android/.idea/libraries/Gradle__com_facebook_fresco_fbcore_2_5_0_aar.xml +0 -18
- package/android/.idea/libraries/Gradle__com_facebook_fresco_fresco_2_5_0_aar.xml +0 -18
- package/android/.idea/libraries/Gradle__com_facebook_fresco_imagepipeline_2_5_0_aar.xml +0 -18
- package/android/.idea/libraries/Gradle__com_facebook_fresco_imagepipeline_base_2_5_0_aar.xml +0 -18
- package/android/.idea/libraries/Gradle__com_facebook_fresco_imagepipeline_native_2_5_0_aar.xml +0 -15
- package/android/.idea/libraries/Gradle__com_facebook_fresco_imagepipeline_okhttp3_2_5_0_aar.xml +0 -15
- package/android/.idea/libraries/Gradle__com_facebook_fresco_memory_type_ashmem_2_5_0_aar.xml +0 -15
- package/android/.idea/libraries/Gradle__com_facebook_fresco_memory_type_java_2_5_0_aar.xml +0 -15
- package/android/.idea/libraries/Gradle__com_facebook_fresco_memory_type_native_2_5_0_aar.xml +0 -15
- package/android/.idea/libraries/Gradle__com_facebook_fresco_nativeimagefilters_2_5_0_aar.xml +0 -15
- package/android/.idea/libraries/Gradle__com_facebook_fresco_nativeimagetranscoder_2_5_0_aar.xml +0 -15
- package/android/.idea/libraries/Gradle__com_facebook_fresco_ui_common_2_5_0_aar.xml +0 -15
- package/android/.idea/libraries/Gradle__com_facebook_infer_annotation_infer_annotation_0_18_0.xml +0 -13
- package/android/.idea/libraries/Gradle__com_facebook_react_react_native_0_66_1_aar.xml +0 -14
- package/android/.idea/libraries/Gradle__com_facebook_soloader_annotation_0_10_1.xml +0 -13
- package/android/.idea/libraries/Gradle__com_facebook_soloader_nativeloader_0_10_1.xml +0 -13
- package/android/.idea/libraries/Gradle__com_facebook_soloader_soloader_0_10_1_aar.xml +0 -15
- package/android/.idea/libraries/Gradle__com_facebook_yoga_proguard_annotations_1_19_0.xml +0 -13
- package/android/.idea/libraries/Gradle__com_google_code_findbugs_jsr305_3_0_2.xml +0 -13
- package/android/.idea/libraries/Gradle__com_googlecode_mp4parser_isoparser_1_0_6.xml +0 -13
- package/android/.idea/libraries/Gradle__com_squareup_okhttp3_okhttp_4_9_1.xml +0 -13
- package/android/.idea/libraries/Gradle__com_squareup_okhttp3_okhttp_urlconnection_4_9_1.xml +0 -13
- package/android/.idea/libraries/Gradle__com_squareup_okio_okio_2_9_0.xml +0 -13
- package/android/.idea/libraries/Gradle__io_github_lizhangqu_coreprogress_1_0_2_aar.xml +0 -18
- package/android/.idea/libraries/Gradle__javax_inject_javax_inject_1.xml +0 -13
- package/android/.idea/libraries/Gradle__org_aspectj_aspectjrt_1_8_2.xml +0 -13
- package/android/.idea/libraries/Gradle__org_jetbrains_annotations_13_0.xml +0 -13
- package/android/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_annotations_jvm_1_3_72.xml +0 -13
- package/android/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_1_4_10.xml +0 -13
- package/android/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_common_1_4_10.xml +0 -13
- package/android/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_jdk7_1_4_10.xml +0 -13
- package/android/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_jdk8_1_4_10.xml +0 -13
- package/android/.idea/libraries/Gradle__org_jetbrains_kotlinx_kotlinx_coroutines_android_1_4_0.xml +0 -13
- package/android/.idea/libraries/Gradle__org_jetbrains_kotlinx_kotlinx_coroutines_core_jvm_1_4_0.xml +0 -13
- package/android/.idea/misc.xml +0 -9
- package/android/.idea/modules/android.iml +0 -138
- package/android/.idea/modules.xml +0 -8
- package/android/.idea/vcs.xml +0 -6
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +0 -5
- package/android/gradlew +0 -183
- package/android/gradlew.bat +0 -100
- package/android/local.properties +0 -8
- package/ios/Compressor.m +0 -351
- package/ios/Compressor.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
- package/ios/Compressor.xcodeproj/project.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/Compressor.xcodeproj/xcshareddata/xcschemes/Compressor.xcscheme +0 -67
- package/ios/Compressor.xcodeproj/xcuserdata/apple.xcuserdatad/xcschemes/xcschememanagement.plist +0 -22
package/ios/Compressor.m
DELETED
|
@@ -1,351 +0,0 @@
|
|
|
1
|
-
#import "Compressor.h"
|
|
2
|
-
#import <React/RCTBridgeModule.h>
|
|
3
|
-
//Image
|
|
4
|
-
#import "Image/ImageCompressor.h"
|
|
5
|
-
#import "Image/ImageCompressorOptions.h"
|
|
6
|
-
#import <React/RCTEventEmitter.h>
|
|
7
|
-
#import <AVFoundation/AVFoundation.h>
|
|
8
|
-
|
|
9
|
-
#define AlAsset_Library_Scheme @"assets-library"
|
|
10
|
-
@implementation Compressor
|
|
11
|
-
AVAssetWriter *assetWriter=nil;
|
|
12
|
-
static NSArray *metadatas;
|
|
13
|
-
|
|
14
|
-
- (NSArray *)metadatas
|
|
15
|
-
{
|
|
16
|
-
if (!metadatas) {
|
|
17
|
-
metadatas = @[
|
|
18
|
-
@"albumName",
|
|
19
|
-
@"artist",
|
|
20
|
-
@"comment",
|
|
21
|
-
@"copyrights",
|
|
22
|
-
@"creationDate",
|
|
23
|
-
@"date",
|
|
24
|
-
@"encodedby",
|
|
25
|
-
@"genre",
|
|
26
|
-
@"language",
|
|
27
|
-
@"location",
|
|
28
|
-
@"lastModifiedDate",
|
|
29
|
-
@"performer",
|
|
30
|
-
@"publisher",
|
|
31
|
-
@"title"
|
|
32
|
-
];
|
|
33
|
-
}
|
|
34
|
-
return metadatas;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
RCT_EXPORT_MODULE()
|
|
38
|
-
|
|
39
|
-
//Image
|
|
40
|
-
RCT_EXPORT_METHOD(
|
|
41
|
-
image_compress: (NSString*) imagePath
|
|
42
|
-
optionsDict: (NSDictionary*) optionsDict
|
|
43
|
-
resolver: (RCTPromiseResolveBlock) resolve
|
|
44
|
-
rejecter: (RCTPromiseRejectBlock) reject) {
|
|
45
|
-
@try {
|
|
46
|
-
ImageCompressorOptions *options = [ImageCompressorOptions fromDictionary:optionsDict];
|
|
47
|
-
[ImageCompressor getAbsoluteImagePath:imagePath completionHandler:^(NSString* absoluteImagePath){
|
|
48
|
-
if(options.autoCompress)
|
|
49
|
-
{
|
|
50
|
-
NSString *result = [ImageCompressor autoCompressHandler:absoluteImagePath options:options];
|
|
51
|
-
resolve(result);
|
|
52
|
-
}
|
|
53
|
-
else
|
|
54
|
-
{
|
|
55
|
-
NSString *result = [ImageCompressor manualCompressHandler:absoluteImagePath options:options];
|
|
56
|
-
resolve(result);
|
|
57
|
-
}
|
|
58
|
-
}];
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
@catch (NSException *exception) {
|
|
62
|
-
reject(exception.name, exception.reason, nil);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
//Audio
|
|
67
|
-
RCT_EXPORT_METHOD(
|
|
68
|
-
compress_audio: (NSString*) filePath
|
|
69
|
-
optionsDict: (NSDictionary*) optionsDict
|
|
70
|
-
resolver: (RCTPromiseResolveBlock) resolve
|
|
71
|
-
rejecter: (RCTPromiseRejectBlock) reject) {
|
|
72
|
-
@try {
|
|
73
|
-
if([filePath containsString:@"file://"])
|
|
74
|
-
{
|
|
75
|
-
filePath=[filePath stringByReplacingOccurrencesOfString:@"file://"
|
|
76
|
-
withString:@""];
|
|
77
|
-
}
|
|
78
|
-
NSFileManager *fileManager = [NSFileManager defaultManager];
|
|
79
|
-
BOOL isDir;
|
|
80
|
-
if (![fileManager fileExistsAtPath:filePath isDirectory:&isDir] || isDir){
|
|
81
|
-
NSError *err = [NSError errorWithDomain:@"file not found" code:-15 userInfo:nil];
|
|
82
|
-
reject([NSString stringWithFormat: @"%lu", (long)err.code], err.localizedDescription, err);
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
NSDictionary *assetOptions = @{AVURLAssetPreferPreciseDurationAndTimingKey: @YES};
|
|
87
|
-
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:[NSURL fileURLWithPath:filePath] options:assetOptions];
|
|
88
|
-
NSString *quality=[optionsDict objectForKey:@"quality"];
|
|
89
|
-
NSString *qualityConstant=[self getAudioQualityConstant:quality];
|
|
90
|
-
[self audo_compress_helper:asset qualityConstant:qualityConstant complete:^(NSString *mp3Path, BOOL finished) {
|
|
91
|
-
if(finished)
|
|
92
|
-
{
|
|
93
|
-
resolve([NSString stringWithFormat: @"file:/%@", mp3Path]);
|
|
94
|
-
}
|
|
95
|
-
else
|
|
96
|
-
{
|
|
97
|
-
reject(@"Error", @"Something went wrong", nil);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
}];
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
@catch (NSException *exception) {
|
|
104
|
-
reject(exception.name, exception.reason, nil);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
- (NSString *)getAudioQualityConstant:(NSString *)quality
|
|
108
|
-
{
|
|
109
|
-
NSMutableArray *audioQualityArray = [[NSMutableArray alloc]initWithObjects:@"low", @"medium", @"high", nil];
|
|
110
|
-
int index = [audioQualityArray indexOfObject:quality];
|
|
111
|
-
switch (index) {
|
|
112
|
-
case 0:
|
|
113
|
-
return AVAssetExportPresetLowQuality;
|
|
114
|
-
break;
|
|
115
|
-
case 1:
|
|
116
|
-
return AVAssetExportPresetMediumQuality;
|
|
117
|
-
break;
|
|
118
|
-
case 2:
|
|
119
|
-
return AVAssetExportPresetHighestQuality;
|
|
120
|
-
break;
|
|
121
|
-
}
|
|
122
|
-
return AVAssetExportPresetMediumQuality;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
- (void)audo_compress_helper:(AVURLAsset *)avAsset qualityConstant:(NSString *)qualityConstant complete:(void (^)(NSString *mp3Path, BOOL finished))completeCallback {
|
|
126
|
-
NSString *path;
|
|
127
|
-
if ([avAsset.URL.scheme isEqualToString:AlAsset_Library_Scheme]) {
|
|
128
|
-
path = avAsset.URL.query;
|
|
129
|
-
if (path.length == 0) {
|
|
130
|
-
completeCallback(nil, NO);
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
}else {
|
|
135
|
-
path = avAsset.URL.path;
|
|
136
|
-
if (!path || ![[NSFileManager defaultManager] fileExistsAtPath:path]) {
|
|
137
|
-
completeCallback(nil, NO);
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
NSString *mp3Path = [ImageCompressor generateCacheFilePath:@"m4a"];;
|
|
143
|
-
|
|
144
|
-
if ([[NSFileManager defaultManager] fileExistsAtPath:mp3Path]) {
|
|
145
|
-
if (completeCallback)
|
|
146
|
-
completeCallback(mp3Path, YES);
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
NSURL *mp3Url;
|
|
151
|
-
NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:avAsset];
|
|
152
|
-
|
|
153
|
-
if ([compatiblePresets containsObject:qualityConstant]) {
|
|
154
|
-
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc]
|
|
155
|
-
initWithAsset:avAsset
|
|
156
|
-
presetName:AVAssetExportPresetAppleM4A];
|
|
157
|
-
|
|
158
|
-
mp3Url = [NSURL fileURLWithPath:mp3Path];
|
|
159
|
-
exportSession.outputURL = mp3Url;
|
|
160
|
-
exportSession.shouldOptimizeForNetworkUse = YES;
|
|
161
|
-
exportSession.outputFileType = AVFileTypeAppleM4A;
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
[exportSession exportAsynchronouslyWithCompletionHandler:^{
|
|
165
|
-
BOOL finished = NO;
|
|
166
|
-
switch ([exportSession status]) {
|
|
167
|
-
case AVAssetExportSessionStatusFailed:
|
|
168
|
-
NSLog(@"AVAssetExportSessionStatusFailed, error:%@.", exportSession.error);
|
|
169
|
-
break;
|
|
170
|
-
|
|
171
|
-
case AVAssetExportSessionStatusCancelled:
|
|
172
|
-
NSLog(@"AVAssetExportSessionStatusCancelled.");
|
|
173
|
-
break;
|
|
174
|
-
|
|
175
|
-
case AVAssetExportSessionStatusCompleted:
|
|
176
|
-
NSLog(@"AVAssetExportSessionStatusCompleted.");
|
|
177
|
-
finished = YES;
|
|
178
|
-
break;
|
|
179
|
-
|
|
180
|
-
case AVAssetExportSessionStatusUnknown:
|
|
181
|
-
NSLog(@"AVAssetExportSessionStatusUnknown");
|
|
182
|
-
break;
|
|
183
|
-
|
|
184
|
-
case AVAssetExportSessionStatusWaiting:
|
|
185
|
-
NSLog(@"AVAssetExportSessionStatusWaiting");
|
|
186
|
-
break;
|
|
187
|
-
|
|
188
|
-
case AVAssetExportSessionStatusExporting:
|
|
189
|
-
NSLog(@"AVAssetExportSessionStatusExporting");
|
|
190
|
-
break;
|
|
191
|
-
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
if (completeCallback)
|
|
195
|
-
completeCallback(mp3Path, finished);
|
|
196
|
-
}];
|
|
197
|
-
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
//general
|
|
204
|
-
RCT_EXPORT_METHOD(
|
|
205
|
-
generateFilePath: (NSString*) extension
|
|
206
|
-
resolver: (RCTPromiseResolveBlock) resolve
|
|
207
|
-
rejecter: (RCTPromiseRejectBlock) reject) {
|
|
208
|
-
@try {
|
|
209
|
-
NSString *outputUri =[ImageCompressor generateCacheFilePath:extension];
|
|
210
|
-
resolve(outputUri);
|
|
211
|
-
}
|
|
212
|
-
@catch (NSException *exception) {
|
|
213
|
-
reject(exception.name, exception.reason, nil);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
RCT_EXPORT_METHOD(
|
|
218
|
-
getRealPath: (NSString*) path
|
|
219
|
-
type: (NSString*) type
|
|
220
|
-
resolver: (RCTPromiseResolveBlock) resolve
|
|
221
|
-
rejecter: (RCTPromiseRejectBlock) reject) {
|
|
222
|
-
@try {
|
|
223
|
-
if([type isEqualToString:@"video"])
|
|
224
|
-
{
|
|
225
|
-
[ImageCompressor getAbsoluteVideoPath:path completionHandler:^(NSString* absoluteImagePath){
|
|
226
|
-
resolve(absoluteImagePath);
|
|
227
|
-
}];
|
|
228
|
-
}
|
|
229
|
-
else
|
|
230
|
-
{
|
|
231
|
-
[ImageCompressor getAbsoluteImagePath:path completionHandler:^(NSString* absoluteImagePath){
|
|
232
|
-
resolve(absoluteImagePath);
|
|
233
|
-
}];
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
@catch (NSException *exception) {
|
|
237
|
-
reject(exception.name, exception.reason, nil);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
//general
|
|
242
|
-
RCT_EXPORT_METHOD(
|
|
243
|
-
getFileSize: (NSString*) filePath
|
|
244
|
-
resolver: (RCTPromiseResolveBlock) resolve
|
|
245
|
-
rejecter: (RCTPromiseRejectBlock) reject) {
|
|
246
|
-
@try {
|
|
247
|
-
if([filePath containsString:@"file://"])
|
|
248
|
-
{
|
|
249
|
-
filePath=[filePath stringByReplacingOccurrencesOfString:@"file://"
|
|
250
|
-
withString:@""];
|
|
251
|
-
}
|
|
252
|
-
NSFileManager *fileManager = [NSFileManager defaultManager];
|
|
253
|
-
BOOL isDir;
|
|
254
|
-
if (![fileManager fileExistsAtPath:filePath isDirectory:&isDir] || isDir){
|
|
255
|
-
NSError *err = [NSError errorWithDomain:@"file not found" code:-15 userInfo:nil];
|
|
256
|
-
reject([NSString stringWithFormat: @"%lu", (long)err.code], err.localizedDescription, err);
|
|
257
|
-
return;
|
|
258
|
-
}
|
|
259
|
-
NSDictionary *attrs = [fileManager attributesOfItemAtPath: filePath error: NULL];
|
|
260
|
-
UInt32 fileSize = [attrs fileSize];
|
|
261
|
-
NSString *fileSizeString = [@(fileSize) stringValue];
|
|
262
|
-
resolve(fileSizeString);
|
|
263
|
-
}
|
|
264
|
-
@catch (NSException *exception) {
|
|
265
|
-
reject(exception.name, exception.reason, nil);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
RCT_EXPORT_METHOD(
|
|
271
|
-
getVideoMetaData: (NSString*) filePath
|
|
272
|
-
resolver: (RCTPromiseResolveBlock) resolve
|
|
273
|
-
rejecter: (RCTPromiseRejectBlock) reject) {
|
|
274
|
-
@try {
|
|
275
|
-
[ImageCompressor getAbsoluteVideoPath:filePath completionHandler:^(NSString *absoluteImagePath) {
|
|
276
|
-
if([absoluteImagePath containsString:@"file://"])
|
|
277
|
-
{
|
|
278
|
-
absoluteImagePath=[absoluteImagePath stringByReplacingOccurrencesOfString:@"file://"
|
|
279
|
-
withString:@""];
|
|
280
|
-
}
|
|
281
|
-
NSFileManager *fileManager = [NSFileManager defaultManager];
|
|
282
|
-
|
|
283
|
-
BOOL isDir;
|
|
284
|
-
if (![fileManager fileExistsAtPath:absoluteImagePath isDirectory:&isDir] || isDir){
|
|
285
|
-
NSError *err = [NSError errorWithDomain:@"file not found" code:-15 userInfo:nil];
|
|
286
|
-
reject([NSString stringWithFormat: @"%lu", (long)err.code], err.localizedDescription, err);
|
|
287
|
-
return;
|
|
288
|
-
}
|
|
289
|
-
NSDictionary *attrs = [fileManager attributesOfItemAtPath: absoluteImagePath error: NULL];
|
|
290
|
-
UInt32 fileSize = [attrs fileSize];
|
|
291
|
-
NSString *fileSizeString = [@(fileSize) stringValue];
|
|
292
|
-
|
|
293
|
-
NSMutableDictionary *result = [NSMutableDictionary new];
|
|
294
|
-
NSDictionary *assetOptions = @{AVURLAssetPreferPreciseDurationAndTimingKey: @YES};
|
|
295
|
-
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:[NSURL fileURLWithPath:absoluteImagePath] options:assetOptions];\
|
|
296
|
-
AVAssetTrack *avAsset = [[asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
|
|
297
|
-
CGSize size = [avAsset naturalSize];
|
|
298
|
-
NSString *extension = [[absoluteImagePath lastPathComponent] pathExtension];
|
|
299
|
-
CMTime time = [asset duration];
|
|
300
|
-
int seconds = ceil(time.value/time.timescale);
|
|
301
|
-
[result setObject:[NSString stringWithFormat: @"%.2f", size.width] forKey:@"width"];
|
|
302
|
-
[result setObject:[NSString stringWithFormat: @"%.2f", size.height] forKey:@"height"];
|
|
303
|
-
[result setObject:extension forKey:@"extension"];
|
|
304
|
-
[result setObject:fileSizeString forKey:@"size"];
|
|
305
|
-
[result setObject:[@(seconds) stringValue] forKey:@"duration"];
|
|
306
|
-
NSArray *keys = [NSArray arrayWithObjects:@"commonMetadata", nil];
|
|
307
|
-
[asset loadValuesAsynchronouslyForKeys:keys completionHandler:^{
|
|
308
|
-
// string keys
|
|
309
|
-
for (NSString *key in [self metadatas]) {
|
|
310
|
-
NSArray *items = [AVMetadataItem metadataItemsFromArray:asset.commonMetadata
|
|
311
|
-
withKey:key
|
|
312
|
-
keySpace:AVMetadataKeySpaceCommon];
|
|
313
|
-
for (AVMetadataItem *item in items) {
|
|
314
|
-
[result setObject:item.value forKey:key];
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
resolve(result);
|
|
318
|
-
}];
|
|
319
|
-
}];
|
|
320
|
-
}
|
|
321
|
-
@catch (NSException *exception) {
|
|
322
|
-
reject(exception.name, exception.reason, nil);
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
@end
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
@interface RCT_EXTERN_MODULE(VideoCompressor, RCTEventEmitter)
|
|
330
|
-
|
|
331
|
-
RCT_EXTERN_METHOD(compress:(NSString *)fileUrl
|
|
332
|
-
withOptions:(NSDictionary *)options
|
|
333
|
-
withResolver:(RCTPromiseResolveBlock)resolve
|
|
334
|
-
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
335
|
-
|
|
336
|
-
RCT_EXTERN_METHOD(upload:(NSString *)fileUrl
|
|
337
|
-
withOptions:(NSDictionary *)options
|
|
338
|
-
withResolver:(RCTPromiseResolveBlock)resolve
|
|
339
|
-
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
340
|
-
|
|
341
|
-
RCT_EXTERN_METHOD(activateBackgroundTask: (NSDictionary *)options
|
|
342
|
-
withResolver:(RCTPromiseResolveBlock)resolve
|
|
343
|
-
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
344
|
-
|
|
345
|
-
RCT_EXTERN_METHOD(deactivateBackgroundTask: (NSDictionary *)options
|
|
346
|
-
withResolver:(RCTPromiseResolveBlock)resolve
|
|
347
|
-
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
348
|
-
|
|
349
|
-
RCT_EXTERN_METHOD(cancelCompression:(NSString *)uuid)
|
|
350
|
-
|
|
351
|
-
@end
|
|
Binary file
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<Scheme
|
|
3
|
-
LastUpgradeVersion = "1240"
|
|
4
|
-
version = "1.3">
|
|
5
|
-
<BuildAction
|
|
6
|
-
parallelizeBuildables = "YES"
|
|
7
|
-
buildImplicitDependencies = "YES">
|
|
8
|
-
<BuildActionEntries>
|
|
9
|
-
<BuildActionEntry
|
|
10
|
-
buildForTesting = "YES"
|
|
11
|
-
buildForRunning = "YES"
|
|
12
|
-
buildForProfiling = "YES"
|
|
13
|
-
buildForArchiving = "YES"
|
|
14
|
-
buildForAnalyzing = "YES">
|
|
15
|
-
<BuildableReference
|
|
16
|
-
BuildableIdentifier = "primary"
|
|
17
|
-
BlueprintIdentifier = "58B511DA1A9E6C8500147676"
|
|
18
|
-
BuildableName = "libCompressor.a"
|
|
19
|
-
BlueprintName = "Compressor"
|
|
20
|
-
ReferencedContainer = "container:Compressor.xcodeproj">
|
|
21
|
-
</BuildableReference>
|
|
22
|
-
</BuildActionEntry>
|
|
23
|
-
</BuildActionEntries>
|
|
24
|
-
</BuildAction>
|
|
25
|
-
<TestAction
|
|
26
|
-
buildConfiguration = "Debug"
|
|
27
|
-
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
|
28
|
-
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
|
29
|
-
shouldUseLaunchSchemeArgsEnv = "YES">
|
|
30
|
-
<Testables>
|
|
31
|
-
</Testables>
|
|
32
|
-
</TestAction>
|
|
33
|
-
<LaunchAction
|
|
34
|
-
buildConfiguration = "Debug"
|
|
35
|
-
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
|
36
|
-
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
|
37
|
-
launchStyle = "0"
|
|
38
|
-
useCustomWorkingDirectory = "NO"
|
|
39
|
-
ignoresPersistentStateOnLaunch = "NO"
|
|
40
|
-
debugDocumentVersioning = "YES"
|
|
41
|
-
debugServiceExtension = "internal"
|
|
42
|
-
allowLocationSimulation = "YES">
|
|
43
|
-
</LaunchAction>
|
|
44
|
-
<ProfileAction
|
|
45
|
-
buildConfiguration = "Release"
|
|
46
|
-
shouldUseLaunchSchemeArgsEnv = "YES"
|
|
47
|
-
savedToolIdentifier = ""
|
|
48
|
-
useCustomWorkingDirectory = "NO"
|
|
49
|
-
debugDocumentVersioning = "YES">
|
|
50
|
-
<MacroExpansion>
|
|
51
|
-
<BuildableReference
|
|
52
|
-
BuildableIdentifier = "primary"
|
|
53
|
-
BlueprintIdentifier = "58B511DA1A9E6C8500147676"
|
|
54
|
-
BuildableName = "libCompressor.a"
|
|
55
|
-
BlueprintName = "Compressor"
|
|
56
|
-
ReferencedContainer = "container:Compressor.xcodeproj">
|
|
57
|
-
</BuildableReference>
|
|
58
|
-
</MacroExpansion>
|
|
59
|
-
</ProfileAction>
|
|
60
|
-
<AnalyzeAction
|
|
61
|
-
buildConfiguration = "Debug">
|
|
62
|
-
</AnalyzeAction>
|
|
63
|
-
<ArchiveAction
|
|
64
|
-
buildConfiguration = "Release"
|
|
65
|
-
revealArchiveInOrganizer = "YES">
|
|
66
|
-
</ArchiveAction>
|
|
67
|
-
</Scheme>
|
package/ios/Compressor.xcodeproj/xcuserdata/apple.xcuserdatad/xcschemes/xcschememanagement.plist
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
|
-
<plist version="1.0">
|
|
4
|
-
<dict>
|
|
5
|
-
<key>SchemeUserState</key>
|
|
6
|
-
<dict>
|
|
7
|
-
<key>Compressor.xcscheme_^#shared#^_</key>
|
|
8
|
-
<dict>
|
|
9
|
-
<key>orderHint</key>
|
|
10
|
-
<integer>0</integer>
|
|
11
|
-
</dict>
|
|
12
|
-
</dict>
|
|
13
|
-
<key>SuppressBuildableAutocreation</key>
|
|
14
|
-
<dict>
|
|
15
|
-
<key>58B511DA1A9E6C8500147676</key>
|
|
16
|
-
<dict>
|
|
17
|
-
<key>primary</key>
|
|
18
|
-
<true/>
|
|
19
|
-
</dict>
|
|
20
|
-
</dict>
|
|
21
|
-
</dict>
|
|
22
|
-
</plist>
|