use ffmpeg-kit-react-native to encode audios
This commit is contained in:
parent
a5e538c13f
commit
6d70253766
|
@ -11,7 +11,7 @@ buildscript {
|
|||
|
||||
ext {
|
||||
buildToolsVersion = "31.0.0"
|
||||
minSdkVersion = 23
|
||||
minSdkVersion = 24
|
||||
compileSdkVersion = 31
|
||||
targetSdkVersion = 31
|
||||
if (System.properties['os.arch'] == "aarch64") {
|
||||
|
@ -28,6 +28,7 @@ buildscript {
|
|||
libre_build = !(isPlay.toBoolean())
|
||||
jitsi_url = "https://github.com/RocketChat/jitsi-maven-repository/raw/master/releases"
|
||||
jitsi_version = "3.7.0"
|
||||
ffmpegKitPackage = "audio"
|
||||
}
|
||||
|
||||
repositories {
|
||||
|
|
|
@ -4,13 +4,16 @@ import { Audio, InterruptionModeAndroid, InterruptionModeIOS } from 'expo-av';
|
|||
import { BorderlessButton } from 'react-native-gesture-handler';
|
||||
import { getInfoAsync } from 'expo-file-system';
|
||||
import { activateKeepAwake, deactivateKeepAwake } from 'expo-keep-awake';
|
||||
import * as FileSystem from 'expo-file-system';
|
||||
import { FFmpegKit, ReturnCode } from 'ffmpeg-kit-react-native';
|
||||
|
||||
import styles from './styles';
|
||||
import I18n from '../../i18n';
|
||||
import { themes } from '../../lib/constants';
|
||||
import { CustomIcon } from '../CustomIcon';
|
||||
import { parseFilename, sanitizeString } from '../../lib/methods/audioFile';
|
||||
import { events, logEvent } from '../../lib/methods/helpers/log';
|
||||
import { TSupportedThemes } from '../../theme';
|
||||
import { CustomIcon } from '../CustomIcon';
|
||||
|
||||
interface IMessageBoxRecordAudioProps {
|
||||
theme: TSupportedThemes;
|
||||
|
@ -157,17 +160,28 @@ export default class RecordAudio extends React.PureComponent<IMessageBoxRecordAu
|
|||
await this.recording.stopAndUnloadAsync();
|
||||
|
||||
const fileURI = this.recording.getURI();
|
||||
const fileData = await getInfoAsync(fileURI as string);
|
||||
const fileInfo = {
|
||||
name: `${Date.now()}.m4a`,
|
||||
mime: 'audio/aac',
|
||||
type: 'audio/aac',
|
||||
store: 'Uploads',
|
||||
path: fileURI,
|
||||
size: fileData.size
|
||||
};
|
||||
const fileName = sanitizeString(fileURI!.substring(fileURI!.lastIndexOf('/') + 1).split('.')[0]);
|
||||
const newFilePath = `${FileSystem.cacheDirectory}/${fileName}.mp3`;
|
||||
const ffmpegCommand = `-hide_banner -y -i ${fileURI} -c:a libmp3lame -qscale:a 2 ${newFilePath}`;
|
||||
|
||||
onFinish(fileInfo);
|
||||
FFmpegKit.execute(ffmpegCommand).then(async session => {
|
||||
const returnCode = await session.getReturnCode();
|
||||
if (ReturnCode.isSuccess(returnCode)) {
|
||||
const fileData = await getInfoAsync(newFilePath);
|
||||
console.log(fileData)
|
||||
const fileInfo = {
|
||||
name: parseFilename(fileData.uri),
|
||||
mime: 'audio/mpeg',
|
||||
type: 'audio/mpeg',
|
||||
store: 'Uploads',
|
||||
path: newFilePath,
|
||||
size: fileData.size
|
||||
};
|
||||
onFinish(fileInfo);
|
||||
} else {
|
||||
console.log('error');
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
logEvent(events.ROOM_AUDIO_FINISH_F);
|
||||
}
|
||||
|
|
|
@ -4,9 +4,9 @@ import { sanitizeLikeString } from '../database/utils';
|
|||
import { store } from '../store/auxStore';
|
||||
import log from './helpers/log';
|
||||
|
||||
const sanitizeString = (value: string) => sanitizeLikeString(value.substring(value.lastIndexOf('/') + 1));
|
||||
export const sanitizeString = (value: string) => sanitizeLikeString(value.substring(value.lastIndexOf('/') + 1));
|
||||
|
||||
const parseFilename = (value: string) => {
|
||||
export const parseFilename = (value: string) => {
|
||||
const extension = value.substring(value.lastIndexOf('.') + 1);
|
||||
const filename = sanitizeString(value.substring(value.lastIndexOf('/') + 1).split('.')[0]);
|
||||
return `${filename}.${extension}`;
|
||||
|
|
|
@ -9,6 +9,7 @@ def all_pods
|
|||
pod 'React-jsi', :path => '../node_modules/react-native/ReactCommon/jsi', :modular_headers => true
|
||||
pod 'simdjson', path: '../node_modules/@nozbe/simdjson'
|
||||
pod 'ReactNativeUiLib', :path => '../node_modules/react-native-ui-lib/lib'
|
||||
pod 'ffmpeg-kit-react-native', :subspecs => ['audio'], :podspec => '../node_modules/ffmpeg-kit-react-native/ffmpeg-kit-react-native.podspec'
|
||||
$RNFirebaseAnalyticsWithoutAdIdSupport = true
|
||||
config = use_native_modules!
|
||||
|
||||
|
|
|
@ -34,6 +34,10 @@ PODS:
|
|||
- React-Core (= 0.68.2)
|
||||
- React-jsi (= 0.68.2)
|
||||
- ReactCommon/turbomodule/core (= 0.68.2)
|
||||
- ffmpeg-kit-ios-audio (5.1)
|
||||
- ffmpeg-kit-react-native/audio (5.1.0):
|
||||
- ffmpeg-kit-ios-audio (= 5.1)
|
||||
- React-Core
|
||||
- Firebase/AnalyticsWithoutAdIdSupport (8.15.0):
|
||||
- Firebase/CoreOnly
|
||||
- FirebaseAnalytics/WithoutAdIdSupport (~> 8.15.0)
|
||||
|
@ -600,6 +604,7 @@ DEPENDENCIES:
|
|||
- EXVideoThumbnails (from `../node_modules/expo-video-thumbnails/ios`)
|
||||
- FBLazyVector (from `../node_modules/react-native/Libraries/FBLazyVector`)
|
||||
- FBReactNativeSpec (from `../node_modules/react-native/React/FBReactNativeSpec`)
|
||||
- ffmpeg-kit-react-native/audio (from `../node_modules/ffmpeg-kit-react-native/ffmpeg-kit-react-native.podspec`)
|
||||
- glog (from `../node_modules/react-native/third-party-podspecs/glog.podspec`)
|
||||
- hermes-engine (~> 0.11.0)
|
||||
- JitsiMeetSDK (from `https://github.com/RocketChat/jitsi-meet-ios-sdk-releases.git`)
|
||||
|
@ -680,6 +685,7 @@ DEPENDENCIES:
|
|||
|
||||
SPEC REPOS:
|
||||
trunk:
|
||||
- ffmpeg-kit-ios-audio
|
||||
- Firebase
|
||||
- FirebaseAnalytics
|
||||
- FirebaseCore
|
||||
|
@ -734,6 +740,8 @@ EXTERNAL SOURCES:
|
|||
:path: "../node_modules/react-native/Libraries/FBLazyVector"
|
||||
FBReactNativeSpec:
|
||||
:path: "../node_modules/react-native/React/FBReactNativeSpec"
|
||||
ffmpeg-kit-react-native:
|
||||
:podspec: "../node_modules/ffmpeg-kit-react-native/ffmpeg-kit-react-native.podspec"
|
||||
glog:
|
||||
:podspec: "../node_modules/react-native/third-party-podspecs/glog.podspec"
|
||||
JitsiMeetSDK:
|
||||
|
@ -902,6 +910,8 @@ SPEC CHECKSUMS:
|
|||
EXVideoThumbnails: 19e055dc3245b53c536da9e0ef9c618fd2118297
|
||||
FBLazyVector: a7a655862f6b09625d11c772296b01cd5164b648
|
||||
FBReactNativeSpec: 66b5770d86bfee27d67b850416dbc7123c4f6311
|
||||
ffmpeg-kit-ios-audio: 6eaf5a3c4249b767328502747a08bfd901a86d3d
|
||||
ffmpeg-kit-react-native: 5950b8015ff2c4fa7c00372d5ce598123902d23d
|
||||
Firebase: 5f8193dff4b5b7c5d5ef72ae54bb76c08e2b841d
|
||||
FirebaseAnalytics: 7761cbadb00a717d8d0939363eb46041526474fa
|
||||
FirebaseCore: 5743c5785c074a794d35f2fff7ecc254a91e08b1
|
||||
|
@ -998,6 +1008,6 @@ SPEC CHECKSUMS:
|
|||
WatermelonDB: 577c61fceff16e9f9103b59d14aee4850c0307b6
|
||||
Yoga: 99652481fcd320aefa4a7ef90095b95acd181952
|
||||
|
||||
PODFILE CHECKSUM: 052cbf741847405abc3b902c9e107c1ebb48b252
|
||||
PODFILE CHECKSUM: fa943eef52304cbca92070cf5ab4be1008650d23
|
||||
|
||||
COCOAPODS: 1.11.3
|
||||
|
|
|
@ -70,6 +70,7 @@
|
|||
"expo-local-authentication": "12.2.0",
|
||||
"expo-video-thumbnails": "6.3.0",
|
||||
"expo-web-browser": "10.2.1",
|
||||
"ffmpeg-kit-react-native": "^5.1.0",
|
||||
"hoist-non-react-statics": "3.3.2",
|
||||
"i18n-js": "3.9.2",
|
||||
"js-base64": "3.6.1",
|
||||
|
|
|
@ -14,6 +14,11 @@ module.exports = {
|
|||
platforms: {
|
||||
android: null
|
||||
}
|
||||
},
|
||||
'ffmpeg-kit-react-native': {
|
||||
platforms: {
|
||||
ios: null
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -10969,6 +10969,11 @@ fetch-retry@^4.1.1:
|
|||
resolved "https://registry.yarnpkg.com/fetch-retry/-/fetch-retry-4.1.1.tgz#fafe0bb22b54f4d0a9c788dff6dd7f8673ca63f3"
|
||||
integrity sha512-e6eB7zN6UBSwGVwrbWVH+gdLnkW9WwHhmq2YDK1Sh30pzx1onRVGBvogTlUeWxwTa+L86NYdo4hFkh7O8ZjSnA==
|
||||
|
||||
ffmpeg-kit-react-native@^5.1.0:
|
||||
version "5.1.0"
|
||||
resolved "https://registry.yarnpkg.com/ffmpeg-kit-react-native/-/ffmpeg-kit-react-native-5.1.0.tgz#7aea05ee642b0b204777ba36994f41ed192ec4ca"
|
||||
integrity sha512-WGuF7wm18vvhr1oCMLRfHIDCwKrmBezWgVtzim6Z3cbDiHeYvDjpm7KJwrvBMwOgekQtP4R4zI9W0ZByoXjMnQ==
|
||||
|
||||
figgy-pudding@^3.5.1:
|
||||
version "3.5.2"
|
||||
resolved "https://registry.yarnpkg.com/figgy-pudding/-/figgy-pudding-3.5.2.tgz#b4eee8148abb01dcf1d1ac34367d59e12fa61d6e"
|
||||
|
|
Loading…
Reference in New Issue