录制语音后我想点击播放按钮播放录制的声音.当我点击停止播放按钮时它必须停止播放.我曾尝试过录制语音的代码.但它以3gpp格式存储文件.所以它不是在ma设备上播放.所以我试图将outputformat更改为’AMR_NB’.但是当我点击停止按钮时它会崩溃.任何人都可以提供代码,否则PLZ帮助我通过编辑我的代码使其工作.@H_404_10@这是我的助手班……
public class AudioRecorder {final MediaRecorder recorder = new MediaRecorder(); final String path; /** * Creates a new audio recording at the given path (relative to root of SD card). */ public AudioRecorder(String path) { this.path = sanitizePath(path); } private String sanitizePath(String path) { if (!path.startsWith("/")) { path = "/" + path; } if (!path.contains(".")) { path += ".3gp"; } return Environment.getExternalStorageDirectory().getabsolutePath() + path; } /** * Starts a new recording. */ public voID start() throws IOException { String state = androID.os.Environment.getExternalStorageState(); if(!state.equals(androID.os.Environment.MEDIA_MOUNTED)) { throw new IOException("SD Card is not mounted. It is " + state + "."); } // make sure the directory we plan to store the recording in exists file directory = new file(path).getParentfile(); if (!directory.exists() && !directory.mkdirs()) { throw new IOException("Path to file Could not be created."); } recorder.setAudioSource(MediaRecorder.AudioSource.MIC); recorder.setoutputFormat(MediaRecorder.OutputFormat.AMR_NB); recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); recorder.setoutputfile(path); recorder.prepare(); recorder.start(); } /** * Stops a recording that has been prevIoUsly started. */ public voID stop() throws IOException { recorder.stop(); recorder.release(); }}
这是我的活动课
public class audiorecording extends Activity {private button start;private button stop;/** Called when the activity is first created. */@OverrIDepublic voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.main); start=(button)findVIEwByID(R.ID.start); stop=(button)findVIEwByID(R.ID.stop); final AudioRecorder recorder = new AudioRecorder("/audiometer/temp"); start.setonClickListener(new OnClickListener() { public voID onClick(VIEw v) { try { recorder.start(); } catch (IOException e) { // Todo auto-generated catch block e.printstacktrace(); } } }) ; //….wait a while stop.setonClickListener(new OnClickListener() { public voID onClick(VIEw v) { try { recorder.stop(); } catch (IOException e) { // Todo auto-generated catch block e.printstacktrace(); } } }) ; }}解决方法 你可以使用 setOutputFormat (int output_format)
Sets the format of the output file produced during recording. Call this after setAudioSource()/setVIDeoSource() but before prepare().@H_404_10@ It is recommended to always use 3GP format when using the H.263 vIDeo encoder and AMR audio encoder. Using an MPEG-4 container format may confuse some desktop players.
Audalyzer适用于AndroID的音频分析仪
This is a simple audio analyser for AndroID. It displays sound readings from the microphone as a waveform display,as a frequency spectrum,and as a dB meter. dB levels are relative to the maximum input level of your device.
Android MediaRecorder
使用MediaRecorder录制音频的常见情况如下:
MediaRecorder recorder = new MediaRecorder(); recorder.setAudioSource(MediaRecorder.AudioSource.MIC); recorder.setoutputFormat(MediaRecorder.OutputFormat.THREE_GPP); recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); recorder.setoutputfile(PATH_name); recorder.prepare(); recorder.start(); // Recording is Now started ... recorder.stop(); recorder.reset(); // You can reuse the object by going back to setAudioSource() step recorder.release(); // Now the object cannot be reused总结
以上是内存溢出为你收集整理的android录音机应用程序全部内容,希望文章能够帮你解决android录音机应用程序所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)