fix: change audio encoding to aac (#5224)
* fix: change audio encoding to aac * remove comment * fix: add support to old audios on iphone * fix: use MediaPlayer implementation * chore: add androidImplementation on loadAsync
This commit is contained in:
parent
7a7193d1ab
commit
4ccf815746
|
@ -20,26 +20,31 @@ interface IMessageBoxRecordAudioProps {
|
|||
onStart: Function;
|
||||
}
|
||||
|
||||
const RECORDING_EXTENSION = '.m4a';
|
||||
const RECORDING_EXTENSION = '.aac';
|
||||
const RECORDING_SETTINGS = {
|
||||
android: {
|
||||
// Settings related to audio encoding.
|
||||
extension: RECORDING_EXTENSION,
|
||||
outputFormat: Audio.RECORDING_OPTION_ANDROID_OUTPUT_FORMAT_MPEG_4,
|
||||
outputFormat: Audio.RECORDING_OPTION_ANDROID_OUTPUT_FORMAT_AAC_ADTS,
|
||||
audioEncoder: Audio.RECORDING_OPTION_ANDROID_AUDIO_ENCODER_AAC,
|
||||
// Settings related to audio quality.
|
||||
sampleRate: Audio.RECORDING_OPTIONS_PRESET_LOW_QUALITY.android.sampleRate,
|
||||
numberOfChannels: Audio.RECORDING_OPTIONS_PRESET_LOW_QUALITY.android.numberOfChannels,
|
||||
bitRate: Audio.RECORDING_OPTIONS_PRESET_LOW_QUALITY.android.bitRate
|
||||
},
|
||||
ios: {
|
||||
// Settings related to audio encoding.
|
||||
extension: RECORDING_EXTENSION,
|
||||
audioQuality: Audio.RECORDING_OPTION_IOS_AUDIO_QUALITY_MIN,
|
||||
audioQuality: Audio.RECORDING_OPTION_IOS_AUDIO_QUALITY_MEDIUM,
|
||||
outputFormat: Audio.RECORDING_OPTION_IOS_OUTPUT_FORMAT_MPEG4AAC,
|
||||
// Settings related to audio quality.
|
||||
sampleRate: Audio.RECORDING_OPTIONS_PRESET_LOW_QUALITY.ios.sampleRate,
|
||||
numberOfChannels: Audio.RECORDING_OPTIONS_PRESET_LOW_QUALITY.ios.numberOfChannels,
|
||||
bitRate: Audio.RECORDING_OPTIONS_PRESET_LOW_QUALITY.ios.bitRate,
|
||||
outputFormat: Audio.RECORDING_OPTION_IOS_OUTPUT_FORMAT_MPEG4AAC
|
||||
bitRate: Audio.RECORDING_OPTIONS_PRESET_LOW_QUALITY.ios.bitRate
|
||||
},
|
||||
web: {}
|
||||
};
|
||||
|
||||
const RECORDING_MODE = {
|
||||
allowsRecordingIOS: true,
|
||||
playsInSilentModeIOS: true,
|
||||
|
@ -159,7 +164,7 @@ export default class RecordAudio extends React.PureComponent<IMessageBoxRecordAu
|
|||
const fileURI = this.recording.getURI();
|
||||
const fileData = await getInfoAsync(fileURI as string);
|
||||
const fileInfo = {
|
||||
name: `${Date.now()}.m4a`,
|
||||
name: `${Date.now()}.aac`,
|
||||
mime: 'audio/aac',
|
||||
type: 'audio/aac',
|
||||
store: 'Uploads',
|
||||
|
|
|
@ -151,7 +151,7 @@ class MessageAudio extends React.Component<IMessageAudioProps, IMessageAudioStat
|
|||
urlToCache: this.getUrl()
|
||||
});
|
||||
if (cachedAudioResult?.exists) {
|
||||
await this.sound.loadAsync({ uri: cachedAudioResult.uri });
|
||||
await this.sound.loadAsync({ uri: cachedAudioResult.uri }, { androidImplementation: 'MediaPlayer' });
|
||||
this.setState({ loading: false, cached: true });
|
||||
return;
|
||||
}
|
||||
|
@ -302,7 +302,7 @@ class MessageAudio extends React.Component<IMessageAudioProps, IMessageAudioStat
|
|||
type: 'audio',
|
||||
mimeType: file.audio_type
|
||||
});
|
||||
await this.sound.loadAsync({ uri: audio });
|
||||
await this.sound.loadAsync({ uri: audio }, { androidImplementation: 'MediaPlayer' });
|
||||
this.setState({ loading: false, cached: true });
|
||||
}
|
||||
} catch {
|
||||
|
@ -341,7 +341,6 @@ class MessageAudio extends React.Component<IMessageAudioProps, IMessageAudioStat
|
|||
|
||||
onValueChange = async (value: number) => {
|
||||
try {
|
||||
this.setState({ currentTime: value });
|
||||
await this.sound.setPositionAsync(value * 1000);
|
||||
} catch {
|
||||
// Do nothing
|
||||
|
|
|
@ -41,7 +41,7 @@ export const getFilename = ({
|
|||
mimeType?: string;
|
||||
}) => {
|
||||
const isTitleTyped = mime.lookup(title);
|
||||
const extension = getExtension(type, mimeType);
|
||||
const extension = getExtension(type, mimeType, url);
|
||||
if (isTitleTyped && title) {
|
||||
if (isTitleTyped === mimeType) {
|
||||
return title;
|
||||
|
@ -65,18 +65,20 @@ export const getFilename = ({
|
|||
return `${filenameFromUrl}.${extension}`;
|
||||
};
|
||||
|
||||
const getExtension = (type: MediaTypes, mimeType?: string) => {
|
||||
const getExtension = (type: MediaTypes, mimeType?: string, url?: string) => {
|
||||
if (!mimeType) {
|
||||
return defaultType[type];
|
||||
}
|
||||
// support audio from older versions
|
||||
if (url?.split('.').pop() === 'm4a') {
|
||||
return 'm4a';
|
||||
}
|
||||
// The library is returning mpag instead of mp3 for audio/mpeg
|
||||
if (mimeType === 'audio/mpeg') {
|
||||
return 'mp3';
|
||||
}
|
||||
// Audios sent by Android devices are in the audio/aac format, which cannot be converted to mp3 by iOS.
|
||||
// However, both platforms support the m4a format, so they can maintain the same behavior.
|
||||
if (mimeType === 'audio/aac') {
|
||||
return 'm4a';
|
||||
return 'aac';
|
||||
}
|
||||
// The return of mime.extension('video/quicktime') is .qt,
|
||||
// this format the iOS isn't recognize and can't save on gallery
|
||||
|
|
Loading…
Reference in New Issue