android  setAudioSource failed

  (2011-05-20 17:14:52) 转载
标签: 

杂谈

分类: android

录音的步骤:

   
    mRecAudioPath=Environment.getExternalStorageDirectory();

   
    File mRecAudioFile=File.createTempFile(strTempFile, ".amr",mRecAudioPath);
    
    mMediaRecorder=new MediaRecorder();
    
    mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);//Call this only before setOutputFormat().这里很重要,如果在setOutputFormat的后面调用的话,会报异常!
    
    mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
    
    mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
    
    mMediaRecorder.setOutputFile(mRecAudioFile.getAbsolutePath());
    
    mMediaRecorder.prepare();
    
    mMediaRecorder.start();

 

采用上面的步骤运行后,后台报了异常

ERROR/AndroidRuntime(287): java.lang.RuntimeException: setAudioSource failed.
原因:权限问题

在AndroidManifest.xml文件中添加:

     android:name="android.permission.RECORD_AUDIO">

更多相关文章

  1. Android中蓝牙使用步骤小结
  2. android Log.isLoggable步骤的使用
  3. android Log.isLoggable步骤的使用
  4. Android(安卓)Studio 运行 java,找不到或无法加载主类
  5. Android中蓝牙使用步骤小结
  6. android 一个奇怪的bug
  7. Android中蓝牙使用步骤小结
  8. Android中蓝牙使用步骤小结
  9. Android中蓝牙使用步骤小结

随机推荐

  1. Android面试系列文章2018之Android部分之
  2. 移动互联网的新宠:Android之缤纷世界
  3. Android扫盲篇
  4. 不要被虚张声势的 Android(安卓)忽悠了
  5. 在 Android(安卓)上使用协程(三) :Real Work
  6. Android(安卓)M新控件之FloatingActionBu
  7. android基础知识17:Android设备常见问题与
  8. android textview xml 属性设置
  9. android socket通信
  10. Android基础介绍