Skip to content

Commit 005d9cd

Browse files
committed
fix: android format mismatches
1 parent 36daec1 commit 005d9cd

File tree

1 file changed

+48
-0
lines changed
  • package/expo-package/src/optionalDependencies

1 file changed

+48
-0
lines changed

package/expo-package/src/optionalDependencies/Audio.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,19 @@ const flattenExpoAudioRecordingOptions = (
267267
...options.ios,
268268
};
269269
} else if (Platform.OS === 'android') {
270+
const audioEncoder = options.android.audioEncoder;
271+
const audioEncoderConfig = audioEncoder
272+
? { audioEncoder: expoAvToExpoAudioAndroidEncoderAdapter(audioEncoder) }
273+
: {};
274+
const outputFormat = options.android.outputFormat;
275+
const outputFormatConfig = outputFormat
276+
? { outputFormat: expoAvToExpoAudioAndroidOutputAdapter(outputFormat) }
277+
: {};
270278
commonOptions = {
271279
...commonOptions,
272280
...options.android,
281+
...audioEncoderConfig,
282+
...outputFormatConfig,
273283
};
274284
}
275285
return commonOptions;
@@ -295,6 +305,44 @@ const expoAvToExpoAudioModeAdapter = (mode: AudioRecordingConfiguration['mode'])
295305
};
296306
};
297307

308+
const expoAvToExpoAudioAndroidEncoderAdapter = (
309+
audioEncoder: AudioRecordingConfiguration['options']['android']['audioEncoder'],
310+
) => {
311+
const encoderMap = {
312+
0: 'default',
313+
1: 'amr_nb',
314+
2: 'amr_wb',
315+
3: 'aac',
316+
4: 'he_aac',
317+
5: 'aac_eld',
318+
};
319+
320+
return Object.keys(encoderMap).includes(audioEncoder.toString())
321+
? encoderMap[audioEncoder]
322+
: 'default';
323+
};
324+
325+
const expoAvToExpoAudioAndroidOutputAdapter = (
326+
outputFormat: AudioRecordingConfiguration['options']['android']['outputFormat'],
327+
) => {
328+
const outputFormatMap = {
329+
0: 'default',
330+
1: '3gp',
331+
2: 'mpeg4',
332+
3: 'amrnb',
333+
4: 'amrwb',
334+
5: 'default',
335+
6: 'aac_adts',
336+
7: 'default',
337+
8: 'mpeg2ts',
338+
9: 'webm',
339+
};
340+
341+
return Object.keys(outputFormatMap).includes(outputFormat.toString())
342+
? outputFormatMap[outputFormat]
343+
: 'default';
344+
};
345+
298346
// Always try to prioritize expo-audio if it's there.
299347
export const Audio = ExpoRecordingComponent
300348
? new _AudioExpoAudio()

0 commit comments

Comments
 (0)