├── .gitignore ├── LICENSE ├── README.md ├── RNAudioTranscoder ├── RNAudioTranscoder.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ └── RNAudioTranscoder.xcscmblueprint └── RNAudioTranscoder │ ├── RNAudioTranscoder.h │ └── RNAudioTranscoder.m ├── android ├── build.gradle └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── com │ └── rnaudiotranscoder │ ├── Optional.java │ ├── RNAudioTranscoder.java │ └── RNAudioTranscoderPackage.java ├── index.js ├── jsconfig.json ├── package.json └── radweb-react-native-audio-transcoder.podspec /.gitignore: -------------------------------------------------------------------------------- 1 | # 2 | ## General 3 | # 4 | 5 | .idea 6 | 7 | # 8 | ## JavaScript 9 | # 10 | 11 | node_modules 12 | 13 | # 14 | ## XCode 15 | # 16 | 17 | # Build generated 18 | build/ 19 | DerivedData/ 20 | 21 | # Various settings 22 | *.pbxuser 23 | !default.pbxuser 24 | *.mode1v3 25 | !default.mode1v3 26 | *.mode2v3 27 | !default.mode2v3 28 | *.perspectivev3 29 | !default.perspectivev3 30 | xcuserdata/ 31 | .DS_Store 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2017 Radweb Ltd 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Setup 2 | 3 | - Install this repository via yarn 4 | - Run `react-native link react-native-audio-transcoder` 5 | 6 | ## Android 7 | 8 | No additional steps required 9 | 10 | ## iOS 11 | 12 | - Add the `AVMediaFoundation` library to your root react native project 13 | 14 | # Interface 15 | 16 | ```javascript 17 | import { transcode } from 'react-native-audio-transcoder' 18 | 19 | const myFilePath = getFilePath() 20 | const myNewFile = myFilePath.replace('aac', 'mp3') 21 | 22 | transcode(myFilePath, myNewFile) 23 | .then(() => console.log('Party!')) 24 | ``` -------------------------------------------------------------------------------- /RNAudioTranscoder/RNAudioTranscoder.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | BFE0FDB41E7FEA6500078E96 /* RNAudioTranscoder.m in Sources */ = {isa = PBXBuildFile; fileRef = BFE0FDB31E7FEA6500078E96 /* RNAudioTranscoder.m */; }; 11 | BFE0FDB51E7FEA6500078E96 /* RNAudioTranscoder.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = BFE0FDB21E7FEA6500078E96 /* RNAudioTranscoder.h */; }; 12 | /* End PBXBuildFile section */ 13 | 14 | /* Begin PBXCopyFilesBuildPhase section */ 15 | BFE0FDAD1E7FEA6500078E96 /* CopyFiles */ = { 16 | isa = PBXCopyFilesBuildPhase; 17 | buildActionMask = 2147483647; 18 | dstPath = "include/$(PRODUCT_NAME)"; 19 | dstSubfolderSpec = 16; 20 | files = ( 21 | BFE0FDB51E7FEA6500078E96 /* RNAudioTranscoder.h in CopyFiles */, 22 | ); 23 | runOnlyForDeploymentPostprocessing = 0; 24 | }; 25 | /* End PBXCopyFilesBuildPhase section */ 26 | 27 | /* Begin PBXFileReference section */ 28 | BFE0FDAF1E7FEA6500078E96 /* libRNAudioTranscoder.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRNAudioTranscoder.a; sourceTree = BUILT_PRODUCTS_DIR; }; 29 | BFE0FDB21E7FEA6500078E96 /* RNAudioTranscoder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNAudioTranscoder.h; sourceTree = ""; }; 30 | BFE0FDB31E7FEA6500078E96 /* RNAudioTranscoder.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNAudioTranscoder.m; sourceTree = ""; }; 31 | /* End PBXFileReference section */ 32 | 33 | /* Begin PBXFrameworksBuildPhase section */ 34 | BFE0FDAC1E7FEA6500078E96 /* Frameworks */ = { 35 | isa = PBXFrameworksBuildPhase; 36 | buildActionMask = 2147483647; 37 | files = ( 38 | ); 39 | runOnlyForDeploymentPostprocessing = 0; 40 | }; 41 | /* End PBXFrameworksBuildPhase section */ 42 | 43 | /* Begin PBXGroup section */ 44 | BFE0FDA61E7FEA6500078E96 = { 45 | isa = PBXGroup; 46 | children = ( 47 | BFE0FDB11E7FEA6500078E96 /* RNAudioTranscoder */, 48 | BFE0FDB01E7FEA6500078E96 /* Products */, 49 | ); 50 | sourceTree = ""; 51 | }; 52 | BFE0FDB01E7FEA6500078E96 /* Products */ = { 53 | isa = PBXGroup; 54 | children = ( 55 | BFE0FDAF1E7FEA6500078E96 /* libRNAudioTranscoder.a */, 56 | ); 57 | name = Products; 58 | sourceTree = ""; 59 | }; 60 | BFE0FDB11E7FEA6500078E96 /* RNAudioTranscoder */ = { 61 | isa = PBXGroup; 62 | children = ( 63 | BFE0FDB21E7FEA6500078E96 /* RNAudioTranscoder.h */, 64 | BFE0FDB31E7FEA6500078E96 /* RNAudioTranscoder.m */, 65 | ); 66 | path = RNAudioTranscoder; 67 | sourceTree = ""; 68 | }; 69 | /* End PBXGroup section */ 70 | 71 | /* Begin PBXNativeTarget section */ 72 | BFE0FDAE1E7FEA6500078E96 /* RNAudioTranscoder */ = { 73 | isa = PBXNativeTarget; 74 | buildConfigurationList = BFE0FDB81E7FEA6500078E96 /* Build configuration list for PBXNativeTarget "RNAudioTranscoder" */; 75 | buildPhases = ( 76 | BFE0FDAB1E7FEA6500078E96 /* Sources */, 77 | BFE0FDAC1E7FEA6500078E96 /* Frameworks */, 78 | BFE0FDAD1E7FEA6500078E96 /* CopyFiles */, 79 | ); 80 | buildRules = ( 81 | ); 82 | dependencies = ( 83 | ); 84 | name = RNAudioTranscoder; 85 | productName = RNAudioTranscoder; 86 | productReference = BFE0FDAF1E7FEA6500078E96 /* libRNAudioTranscoder.a */; 87 | productType = "com.apple.product-type.library.static"; 88 | }; 89 | /* End PBXNativeTarget section */ 90 | 91 | /* Begin PBXProject section */ 92 | BFE0FDA71E7FEA6500078E96 /* Project object */ = { 93 | isa = PBXProject; 94 | attributes = { 95 | LastUpgradeCheck = 0820; 96 | ORGANIZATIONNAME = Radweb; 97 | TargetAttributes = { 98 | BFE0FDAE1E7FEA6500078E96 = { 99 | CreatedOnToolsVersion = 8.2.1; 100 | ProvisioningStyle = Automatic; 101 | }; 102 | }; 103 | }; 104 | buildConfigurationList = BFE0FDAA1E7FEA6500078E96 /* Build configuration list for PBXProject "RNAudioTranscoder" */; 105 | compatibilityVersion = "Xcode 3.2"; 106 | developmentRegion = English; 107 | hasScannedForEncodings = 0; 108 | knownRegions = ( 109 | en, 110 | ); 111 | mainGroup = BFE0FDA61E7FEA6500078E96; 112 | productRefGroup = BFE0FDB01E7FEA6500078E96 /* Products */; 113 | projectDirPath = ""; 114 | projectRoot = ""; 115 | targets = ( 116 | BFE0FDAE1E7FEA6500078E96 /* RNAudioTranscoder */, 117 | ); 118 | }; 119 | /* End PBXProject section */ 120 | 121 | /* Begin PBXSourcesBuildPhase section */ 122 | BFE0FDAB1E7FEA6500078E96 /* Sources */ = { 123 | isa = PBXSourcesBuildPhase; 124 | buildActionMask = 2147483647; 125 | files = ( 126 | BFE0FDB41E7FEA6500078E96 /* RNAudioTranscoder.m in Sources */, 127 | ); 128 | runOnlyForDeploymentPostprocessing = 0; 129 | }; 130 | /* End PBXSourcesBuildPhase section */ 131 | 132 | /* Begin XCBuildConfiguration section */ 133 | BFE0FDB61E7FEA6500078E96 /* Debug */ = { 134 | isa = XCBuildConfiguration; 135 | buildSettings = { 136 | ALWAYS_SEARCH_USER_PATHS = NO; 137 | CLANG_ANALYZER_NONNULL = YES; 138 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 139 | CLANG_CXX_LIBRARY = "libc++"; 140 | CLANG_ENABLE_MODULES = YES; 141 | CLANG_ENABLE_OBJC_ARC = YES; 142 | CLANG_WARN_BOOL_CONVERSION = YES; 143 | CLANG_WARN_CONSTANT_CONVERSION = YES; 144 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 145 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 146 | CLANG_WARN_EMPTY_BODY = YES; 147 | CLANG_WARN_ENUM_CONVERSION = YES; 148 | CLANG_WARN_INFINITE_RECURSION = YES; 149 | CLANG_WARN_INT_CONVERSION = YES; 150 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 151 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 152 | CLANG_WARN_UNREACHABLE_CODE = YES; 153 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 154 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 155 | COPY_PHASE_STRIP = NO; 156 | DEBUG_INFORMATION_FORMAT = dwarf; 157 | ENABLE_STRICT_OBJC_MSGSEND = YES; 158 | ENABLE_TESTABILITY = YES; 159 | GCC_C_LANGUAGE_STANDARD = gnu99; 160 | GCC_DYNAMIC_NO_PIC = NO; 161 | GCC_NO_COMMON_BLOCKS = YES; 162 | GCC_OPTIMIZATION_LEVEL = 0; 163 | GCC_PREPROCESSOR_DEFINITIONS = ( 164 | "DEBUG=1", 165 | "$(inherited)", 166 | ); 167 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 168 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 169 | GCC_WARN_UNDECLARED_SELECTOR = YES; 170 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 171 | GCC_WARN_UNUSED_FUNCTION = YES; 172 | GCC_WARN_UNUSED_VARIABLE = YES; 173 | IPHONEOS_DEPLOYMENT_TARGET = 10.2; 174 | MTL_ENABLE_DEBUG_INFO = YES; 175 | ONLY_ACTIVE_ARCH = YES; 176 | SDKROOT = iphoneos; 177 | }; 178 | name = Debug; 179 | }; 180 | BFE0FDB71E7FEA6500078E96 /* Release */ = { 181 | isa = XCBuildConfiguration; 182 | buildSettings = { 183 | ALWAYS_SEARCH_USER_PATHS = NO; 184 | CLANG_ANALYZER_NONNULL = YES; 185 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 186 | CLANG_CXX_LIBRARY = "libc++"; 187 | CLANG_ENABLE_MODULES = YES; 188 | CLANG_ENABLE_OBJC_ARC = YES; 189 | CLANG_WARN_BOOL_CONVERSION = YES; 190 | CLANG_WARN_CONSTANT_CONVERSION = YES; 191 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 192 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 193 | CLANG_WARN_EMPTY_BODY = YES; 194 | CLANG_WARN_ENUM_CONVERSION = YES; 195 | CLANG_WARN_INFINITE_RECURSION = YES; 196 | CLANG_WARN_INT_CONVERSION = YES; 197 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 198 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 199 | CLANG_WARN_UNREACHABLE_CODE = YES; 200 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 201 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 202 | COPY_PHASE_STRIP = NO; 203 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 204 | ENABLE_NS_ASSERTIONS = NO; 205 | ENABLE_STRICT_OBJC_MSGSEND = YES; 206 | GCC_C_LANGUAGE_STANDARD = gnu99; 207 | GCC_NO_COMMON_BLOCKS = YES; 208 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 209 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 210 | GCC_WARN_UNDECLARED_SELECTOR = YES; 211 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 212 | GCC_WARN_UNUSED_FUNCTION = YES; 213 | GCC_WARN_UNUSED_VARIABLE = YES; 214 | IPHONEOS_DEPLOYMENT_TARGET = 10.2; 215 | MTL_ENABLE_DEBUG_INFO = NO; 216 | SDKROOT = iphoneos; 217 | VALIDATE_PRODUCT = YES; 218 | }; 219 | name = Release; 220 | }; 221 | BFE0FDB91E7FEA6500078E96 /* Debug */ = { 222 | isa = XCBuildConfiguration; 223 | buildSettings = { 224 | LIBRARY_SEARCH_PATHS = ( 225 | "$(inherited)", 226 | "$(PROJECT_DIR)/dependencies/lib", 227 | ); 228 | OTHER_LDFLAGS = "-ObjC"; 229 | PRODUCT_NAME = "$(TARGET_NAME)"; 230 | SKIP_INSTALL = YES; 231 | }; 232 | name = Debug; 233 | }; 234 | BFE0FDBA1E7FEA6500078E96 /* Release */ = { 235 | isa = XCBuildConfiguration; 236 | buildSettings = { 237 | LIBRARY_SEARCH_PATHS = ( 238 | "$(inherited)", 239 | "$(PROJECT_DIR)/dependencies/lib", 240 | ); 241 | OTHER_LDFLAGS = "-ObjC"; 242 | PRODUCT_NAME = "$(TARGET_NAME)"; 243 | SKIP_INSTALL = YES; 244 | }; 245 | name = Release; 246 | }; 247 | /* End XCBuildConfiguration section */ 248 | 249 | /* Begin XCConfigurationList section */ 250 | BFE0FDAA1E7FEA6500078E96 /* Build configuration list for PBXProject "RNAudioTranscoder" */ = { 251 | isa = XCConfigurationList; 252 | buildConfigurations = ( 253 | BFE0FDB61E7FEA6500078E96 /* Debug */, 254 | BFE0FDB71E7FEA6500078E96 /* Release */, 255 | ); 256 | defaultConfigurationIsVisible = 0; 257 | defaultConfigurationName = Release; 258 | }; 259 | BFE0FDB81E7FEA6500078E96 /* Build configuration list for PBXNativeTarget "RNAudioTranscoder" */ = { 260 | isa = XCConfigurationList; 261 | buildConfigurations = ( 262 | BFE0FDB91E7FEA6500078E96 /* Debug */, 263 | BFE0FDBA1E7FEA6500078E96 /* Release */, 264 | ); 265 | defaultConfigurationIsVisible = 0; 266 | defaultConfigurationName = Release; 267 | }; 268 | /* End XCConfigurationList section */ 269 | }; 270 | rootObject = BFE0FDA71E7FEA6500078E96 /* Project object */; 271 | } 272 | -------------------------------------------------------------------------------- /RNAudioTranscoder/RNAudioTranscoder.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /RNAudioTranscoder/RNAudioTranscoder.xcodeproj/project.xcworkspace/xcshareddata/RNAudioTranscoder.xcscmblueprint: -------------------------------------------------------------------------------- 1 | { 2 | "DVTSourceControlWorkspaceBlueprintPrimaryRemoteRepositoryKey" : "81A0005A40A9393C1CC600CF6665A094EB89AAE5", 3 | "DVTSourceControlWorkspaceBlueprintWorkingCopyRepositoryLocationsKey" : { 4 | 5 | }, 6 | "DVTSourceControlWorkspaceBlueprintWorkingCopyStatesKey" : { 7 | "81A0005A40A9393C1CC600CF6665A094EB89AAE5" : 9223372036854775807, 8 | "5E27CBA41412F60913279722722593371D861B06" : 9223372036854775807 9 | }, 10 | "DVTSourceControlWorkspaceBlueprintIdentifierKey" : "196699BE-B2B3-49F0-AC56-1BBC6166462C", 11 | "DVTSourceControlWorkspaceBlueprintWorkingCopyPathsKey" : { 12 | "81A0005A40A9393C1CC600CF6665A094EB89AAE5" : "rnat\/", 13 | "5E27CBA41412F60913279722722593371D861B06" : "rnat\/Submodules\/FFmpegWrapper\/" 14 | }, 15 | "DVTSourceControlWorkspaceBlueprintNameKey" : "RNAudioTranscoder", 16 | "DVTSourceControlWorkspaceBlueprintVersion" : 204, 17 | "DVTSourceControlWorkspaceBlueprintRelativePathToProjectKey" : "RNAudioTranscoder\/RNAudioTranscoder.xcodeproj", 18 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoriesKey" : [ 19 | { 20 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/OpenWatch\/FFmpegWrapper.git", 21 | "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", 22 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "5E27CBA41412F60913279722722593371D861B06" 23 | }, 24 | { 25 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "github.com:Radweb\/react-native-audio-transcoder.git", 26 | "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", 27 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "81A0005A40A9393C1CC600CF6665A094EB89AAE5" 28 | } 29 | ] 30 | } -------------------------------------------------------------------------------- /RNAudioTranscoder/RNAudioTranscoder/RNAudioTranscoder.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | @interface RNAudioTranscoder : NSObject 4 | @end 5 | -------------------------------------------------------------------------------- /RNAudioTranscoder/RNAudioTranscoder/RNAudioTranscoder.m: -------------------------------------------------------------------------------- 1 | #import "RNAudioTranscoder.h" 2 | #import 3 | #import 4 | #import 5 | #import 6 | 7 | @implementation RNAudioTranscoder 8 | 9 | RCT_EXPORT_MODULE(); 10 | 11 | RCT_EXPORT_METHOD( 12 | transcode: (NSDictionary *) obj 13 | resolver:(RCTPromiseResolveBlock) resolve 14 | rejecter: (RCTPromiseRejectBlock) reject 15 | ) { 16 | NSString *inputPath = obj[@"input"]; 17 | NSURL *inputURL = [[NSURL alloc] initFileURLWithPath:inputPath]; 18 | NSString *outputPath = obj[@"output"]; 19 | NSURL *outputURL = [[NSURL alloc] initFileURLWithPath:outputPath]; 20 | 21 | NSError *rgError = nil; 22 | NSRegularExpression *replacer = [NSRegularExpression regularExpressionWithPattern:@"\\.m4a$" 23 | options:NSRegularExpressionCaseInsensitive 24 | error:&rgError]; 25 | 26 | NSString *tempPath = [replacer stringByReplacingMatchesInString:outputPath 27 | options:0 28 | range:NSMakeRange(0, outputPath.length) 29 | withTemplate:@".m4a"]; 30 | 31 | if (rgError != nil) { 32 | reject(@"Failed to create temp path for output", rgError.localizedDescription, rgError); 33 | return; 34 | } 35 | 36 | NSURL *tempUrl = [[NSURL alloc] initFileURLWithPath:tempPath]; 37 | 38 | AVMutableComposition *input = [[AVMutableComposition alloc] init]; 39 | AVURLAsset *track = [AVURLAsset assetWithURL:inputURL]; 40 | 41 | CMTime start = kCMTimeZero; 42 | NSError *error = nil; 43 | 44 | BOOL success = [input insertTimeRange:CMTimeRangeMake(start, track.duration) ofAsset:track atTime:start error:&error]; 45 | 46 | if (!success) { 47 | reject(@"Setup failed", error.localizedDescription, error); 48 | return; 49 | } 50 | 51 | AVAssetExportSession *outputSession = [[AVAssetExportSession alloc] initWithAsset:input presetName:AVAssetExportPresetPassthrough]; 52 | outputSession.metadata = input.metadata; 53 | outputSession.outputURL = tempUrl; 54 | outputSession.outputFileType = AVFileTypeAppleM4A; 55 | 56 | [outputSession exportAsynchronouslyWithCompletionHandler:^{ 57 | 58 | if (outputSession.status == AVAssetExportSessionStatusCompleted) 59 | { 60 | 61 | resolve(@"Successfully encoded audio"); 62 | } 63 | else if (outputSession.status == AVAssetExportSessionStatusCancelled) 64 | { 65 | reject(@"Export Cancelled", @"Exporting audio file was cancelled", nil); 66 | } 67 | else 68 | { 69 | reject(@"Export Failed", outputSession.error.localizedDescription, outputSession.error); 70 | } 71 | 72 | }]; 73 | } 74 | 75 | @end 76 | -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | jcenter() 4 | mavenCentral() 5 | } 6 | 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:1.1.3' 9 | } 10 | } 11 | 12 | apply plugin: 'idea' 13 | 14 | apply plugin: 'com.android.library' 15 | 16 | def DEFAULT_COMPILE_SDK_VERSION = 31 17 | def DEFAULT_BUILD_TOOLS_VERSION = "31.0.0" 18 | def DEFAULT_TARGET_SDK_VERSION = 31 19 | 20 | 21 | android { 22 | compileSdkVersion rootProject.hasProperty('compileSdkVersion') ? rootProject.compileSdkVersion : DEFAULT_COMPILE_SDK_VERSION 23 | buildToolsVersion rootProject.hasProperty('buildToolsVersion') ? rootProject.buildToolsVersion : DEFAULT_BUILD_TOOLS_VERSION 24 | 25 | defaultConfig { 26 | minSdkVersion 21 27 | targetSdkVersion rootProject.hasProperty('targetSdkVersion') ? rootProject.targetSdkVersion : DEFAULT_TARGET_SDK_VERSION 28 | versionCode 1 29 | versionName "1.0" 30 | } 31 | lintOptions { 32 | abortOnError false 33 | } 34 | } 35 | 36 | dependencies { 37 | implementation 'com.facebook.react:react-native:+' 38 | implementation 'com.writingminds:FFmpegAndroid:0.3.2' 39 | } 40 | -------------------------------------------------------------------------------- /android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | -------------------------------------------------------------------------------- /android/src/main/java/com/rnaudiotranscoder/Optional.java: -------------------------------------------------------------------------------- 1 | package com.rnaudiotranscoder; 2 | 3 | /** 4 | * React native doesn't seem to play nicely with the JDK 8 Optional class. 5 | * This class represents the mvp of the Optional interface that we need. 6 | * @param 7 | */ 8 | public final class Optional { 9 | /** 10 | * Whether or not this Optional contains a value 11 | */ 12 | public final boolean exists; 13 | /** 14 | * The value represented by this optional 15 | * INVARIANT: If this#exists is true, this parameter will never be null 16 | */ 17 | public final T value; 18 | 19 | /** 20 | * Creates an empty optional 21 | */ 22 | private Optional() { 23 | exists = false; 24 | value = null; 25 | } 26 | 27 | /** 28 | * Creates an existant optional 29 | * @param value The value this optional represents 30 | */ 31 | private Optional(T value) { 32 | exists = true; 33 | this.value = value; 34 | } 35 | 36 | /** 37 | * Create a new optional value with the given existant value. 38 | * Will throw a null pointer exception if the value is null. 39 | * @param existant A value that exists 40 | * @param The type that this optional represents 41 | * @return An optional of the type passed in as the existant parameter 42 | */ 43 | public static Optional of(T existant) { 44 | if (existant == null) throw new NullPointerException("Cannot construct existant optional of null"); 45 | return new Optional<>(existant); 46 | } 47 | 48 | /** 49 | * Create an optional representing a non existant value 50 | * @return An empty optional 51 | */ 52 | public static Optional empty() { 53 | return new Optional<>(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /android/src/main/java/com/rnaudiotranscoder/RNAudioTranscoder.java: -------------------------------------------------------------------------------- 1 | package com.rnaudiotranscoder; 2 | 3 | import android.content.Context; 4 | import android.net.Uri; 5 | import android.util.Log; 6 | 7 | import com.github.hiteshsondhi88.libffmpeg.ExecuteBinaryResponseHandler; 8 | import com.github.hiteshsondhi88.libffmpeg.FFmpeg; 9 | import com.github.hiteshsondhi88.libffmpeg.LoadBinaryResponseHandler; 10 | import com.github.hiteshsondhi88.libffmpeg.exceptions.FFmpegCommandAlreadyRunningException; 11 | import com.github.hiteshsondhi88.libffmpeg.exceptions.FFmpegNotSupportedException; 12 | 13 | import com.facebook.react.bridge.NativeModule; 14 | import com.facebook.react.bridge.ReactApplicationContext; 15 | import com.facebook.react.bridge.ReactContext; 16 | import com.facebook.react.bridge.ReactContextBaseJavaModule; 17 | import com.facebook.react.bridge.ReactMethod; 18 | import com.facebook.react.bridge.Promise; 19 | import com.facebook.react.bridge.ReadableMap; 20 | import com.facebook.react.bridge.WritableMap; 21 | import com.facebook.react.bridge.Arguments; 22 | import com.facebook.react.modules.core.DeviceEventManagerModule; 23 | 24 | public final class RNAudioTranscoder extends ReactContextBaseJavaModule { 25 | 26 | private final FFmpeg ffmpeg; 27 | 28 | public final String COMMAND_FORMAT = "-i %s -codec:a libmp3lame -qscale:a 2 %s"; 29 | public final String TAG = "RNAudioTranscoder"; 30 | 31 | public RNAudioTranscoder (final ReactApplicationContext context) { 32 | super(context); 33 | ffmpeg = FFmpeg.getInstance(context); 34 | } 35 | 36 | @Override 37 | public final String getName() { 38 | return "RNAudioTranscoder"; 39 | } 40 | 41 | @ReactMethod 42 | public final void transcode(final ReadableMap options, final Promise promise) { 43 | final Optional paramErrors = this.checkRequiredOptions(options); 44 | if (paramErrors.exists) { 45 | promise.reject(paramErrors.value); 46 | } else { 47 | try { 48 | ffmpeg.loadBinary(new LoadBinaryResponseHandler() { 49 | @Override 50 | public void onFailure() { 51 | Log.e(TAG, "Failed to load ffmpeg"); 52 | promise.reject("Failed to load ffmpeg binary"); 53 | } 54 | @Override 55 | public void onSuccess() { 56 | final String input = options.getString("input"); 57 | final String output = options.getString("output"); 58 | final String[] command = createFFmpegCommand(input, output); 59 | try { 60 | ffmpeg.execute(command, new ExecuteBinaryResponseHandler() { 61 | @Override 62 | public void onFailure(String s) { 63 | promise.reject(s); 64 | } 65 | 66 | @Override 67 | public void onSuccess(String s) { 68 | promise.resolve(makeMessagePayload(s)); 69 | } 70 | }); 71 | } catch (FFmpegCommandAlreadyRunningException e) { 72 | promise.reject(e.getMessage()); 73 | } 74 | } 75 | }); 76 | } catch (FFmpegNotSupportedException e) { 77 | Log.e(TAG, "FFMPEG NOT SUPPORTED"); 78 | promise.reject(e.getMessage()); 79 | } 80 | } 81 | } 82 | 83 | private final ReadableMap makeMessagePayload(final String message) { 84 | final WritableMap payload = Arguments.createMap(); 85 | payload.putString("message", message); 86 | return payload; 87 | } 88 | 89 | private final String[] createFFmpegCommand(final String input, final String output) { 90 | return String.format(COMMAND_FORMAT, input, output).split(" "); 91 | } 92 | 93 | private final Optional checkRequiredOptions(final ReadableMap options) { 94 | if (!options.hasKey("input")) return Optional.of("Missing required parameter 'input'"); 95 | if (!options.hasKey("output")) return Optional.of("Missing required parameter 'output'"); 96 | 97 | return Optional.empty(); 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /android/src/main/java/com/rnaudiotranscoder/RNAudioTranscoderPackage.java: -------------------------------------------------------------------------------- 1 | package com.rnaudiotranscoder; 2 | 3 | import java.util.*; 4 | 5 | import com.facebook.react.ReactPackage; 6 | import com.facebook.react.bridge.NativeModule; 7 | import com.facebook.react.bridge.JavaScriptModule; 8 | import com.facebook.react.bridge.ReactApplicationContext; 9 | import com.facebook.react.uimanager.ViewManager; 10 | 11 | public final class RNAudioTranscoderPackage implements ReactPackage { 12 | 13 | @Override 14 | public final List createNativeModules(ReactApplicationContext reactContext) { 15 | List modules = new ArrayList<>(); 16 | modules.add(new RNAudioTranscoder(reactContext)); 17 | return modules; 18 | } 19 | 20 | // Deprecated in RN 0.47 21 | public final List> createJSModules() { 22 | return Collections.emptyList(); 23 | } 24 | 25 | @Override 26 | public final List createViewManagers(ReactApplicationContext reactContext) { 27 | return Arrays.asList(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const { NativeModules } = require('react-native') 2 | const RNAudioTranscoder = NativeModules.RNAudioTranscoder 3 | 4 | /** 5 | * Attempt to transcode the audio file at the specified input path to the one at the specified output path 6 | * Return value indicates success. 7 | * @param input Path to the input file 8 | * @param output Path ot the output file. NOTE: Currently this must be an mp3 file 9 | * @param log Optionally catch and log errors, returning false ot indicate failure. Defaults to false, where thrown 10 | * errors in native code will propagate 11 | * @returns {Promise.} 12 | */ 13 | async function transcode(input, output, log = false) { 14 | if (log) { 15 | try { 16 | await RNAudioTranscoder.transcode({ input, output }) 17 | } catch (e) { 18 | console.error(e.message) 19 | return false 20 | } 21 | return true 22 | } 23 | 24 | await RNAudioTranscoder.transcode({ input, output }) 25 | return true 26 | } 27 | 28 | module.exports = { transcode } 29 | -------------------------------------------------------------------------------- /jsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES6", 4 | "module": "commonjs" 5 | } 6 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "radweb-react-native-audio-transcoder", 3 | "version": "0.7.1", 4 | "main": "index.js", 5 | "description": "Transcode audio natively", 6 | "author": [ 7 | "Louis Capitanchik ", 8 | "Wade Urry " 9 | ], 10 | "license": "Apache-2.0", 11 | "private": false 12 | } 13 | -------------------------------------------------------------------------------- /radweb-react-native-audio-transcoder.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = "radweb-react-native-audio-transcoder" 3 | s.version = "0.7.1" 4 | s.summary = "Transcode audio format in react-native" 5 | s.description = <<-DESC 6 | Transcode audio format in react-native 7 | DESC 8 | 9 | s.homepage = "https://github.com/Radweb/react-native-audio-transcoder" 10 | s.license = "Apache-2.0" 11 | s.author = "Radweb" 12 | s.source = { :git => "https://github.com/Radweb/react-native-audio-transcoder.git", :tag => "#{s.version}" } 13 | s.source_files = "RNAudioTranscoder/RNAudioTranscoder" 14 | s.framework = "AVFoundation" 15 | s.dependency "React" 16 | 17 | s.platform = :ios, "8.0" 18 | end 19 | --------------------------------------------------------------------------------