0

在我的 android 应用程序中,我想将我的声音录制为 MP3 文件。但Android的Media Recorder(支持录音的类)似乎不支持MP3格式。它似乎只允许 3gp 和 mpeg4 文件格式。

recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG4);

任何人都可以帮助我或给我一个代码吗?

4

3 回答 3

1

Mp3 编码器在 android 中不可用,但可以使用 Libav/FFMPeg 和 mp3 LAME 对 mp3 进行编码,您可以在此处找到示例代码

于 2014-01-05T08:42:12.973 回答
0

使用此代码,这对我有用:

MediaRecorder   recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
/*  recorder.setAudioEncodingBitRate(32);
recorder.setAudioSamplingRate(44100);*/
recorder.setOutputFile(file.getPath());
recorder.setOnErrorListener(errorListener);
recorder.setOnInfoListener(infoListener);
于 2015-12-10T09:40:13.007 回答
-2

安卓现在正式支持 MP3:

http://developer.android.com/guide/appendix/media-formats.html

核心媒体格式:


格式/编解码器 || 详情 || 支持的文件类型/容器格式


MP3 || 单声道/立体声 8-320Kbps 恒定 (CBR) 或可变比特率 (VBR) || MP3 (.mp3)格式


在此处输入图像描述

您可以将其用作:

mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);

并使用后缀“ .mp3 ”保存文件

于 2015-09-15T13:14:37.773 回答