本文介绍了AudioFlinger不能创造纪录的轨道,状态:-1,需要帮助IFX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 公共类AudioRecorderActivity延伸活动{

  私有静态最终诠释RECORDER_SAMPLERATE = 8000;
  私有静态最终诠释RECORDER_CHANNELS = AudioFormat.CHANNEL_IN_MONO;
  私有静态最终诠释RECORDER_AUDIO_ENCODING = AudioFormat.ENCODING_PCM_16BIT;
  私人AudioRecord记录= NULL;
  私有静态最后字符串变量=AudioRecorderActivity;
  短[] []缓冲区=新的短[256] [160]
  INT九= 0;
  私人布尔停止= FALSE;

  私人无效的startRecording(){

    android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_URGENT_AUDIO);
    尝试 {
      INT N = AudioRecord.getMinBufferSize(
                          RECORDER_SAMPLERATE,
                          RECORDER_CHANNELS,
                          RECORDER_AUDIO_ENCODING)* 20;

      记录=新AudioRecord(AudioSource.MIC,
                    RECORDER_SAMPLERATE,
                    RECORDER_CHANNELS,
                    RECORDER_AUDIO_ENCODING,N);

      recorder.startRecording();

      而(!停){
        短[]缓冲区=缓冲区[IX +%buffers.length]。
        N = recorder.read(缓冲液,0,buffer.length);
      }

    }
    捕获(的Throwable X){
      Log.v(TAG,错误读取语音音频,X);
      x.printStackTrace();
    }
    最后 {
      停止= TRUE;
      STO precording();
    }
  }
}
 

问:虽然code段是基于计算器的的exaple,它不工作请让我知道可能是什么错误呢?

下面是错误消息

  3月12日至二十○日:44:32.271:E / AudioRecord(224):AudioFlinger不能创造纪录的轨道,状态:-1
三月12号至20日:44:32.271:E / AudioRecord-JNI(224):错误创建AudioRecord实例:初始化检查失败。
三月12号至20日:44:32.271:E / AudioRecord Java的(224):[android.media.AudioRecord]错误code初始化本地AudioRecord对象时-20。
 

解决方案

添加RECORD_AUDIO权限的Andr​​oidManifest.xml

 <使用-权限的Andr​​oid:名称=android.permission.RECORD_AUDIO/>
 
public class AudioRecorderActivity extends Activity {

  private static final int RECORDER_SAMPLERATE        = 8000;
  private static final int RECORDER_CHANNELS          = AudioFormat.CHANNEL_IN_MONO;
  private static final int RECORDER_AUDIO_ENCODING    = AudioFormat.ENCODING_PCM_16BIT;
  private AudioRecord recorder                        = null;
  private static final String TAG                     = "AudioRecorderActivity";
  short[][]   buffers                                 = new short[256][160];
  int         ix                                      = 0;
  private boolean     stopped                         = false;

  private void startRecording() {

    android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_URGENT_AUDIO);
    try {
      int N = AudioRecord.getMinBufferSize (
                          RECORDER_SAMPLERATE,
                          RECORDER_CHANNELS,
                          RECORDER_AUDIO_ENCODING) * 20;

      recorder = new  AudioRecord(AudioSource.MIC,
                    RECORDER_SAMPLERATE,
                    RECORDER_CHANNELS,
                    RECORDER_AUDIO_ENCODING,N );

      recorder.startRecording();

      while(!stopped) {
        short[] buffer = buffers[ix++ % buffers.length];
        N = recorder.read(buffer,0,buffer.length);
      }

    }
    catch(Throwable x) {
      Log.v(TAG,"Error reading voice audio",x);
      x.printStackTrace();
    }
    finally {
      stopped = true;
      stopRecording();
    }
  }
}

Question : Though the code snippet is based on an exaple from StackOverflow, it is not workingPlease let me know what could be the mistake ?

Here is the Error Message

12-20 03:44:32.271: E/AudioRecord(224): AudioFlinger could not create record track, status: -1
12-20 03:44:32.271: E/AudioRecord-JNI(224): Error creating AudioRecord instance: initialization check failed.
12-20 03:44:32.271: E/AudioRecord-Java(224): [ android.media.AudioRecord ] Error code -20 when initializing native AudioRecord object.
解决方案

Add record_audio permission to AndroidManifest.xml

<uses-permission android:name="android.permission.RECORD_AUDIO" />

这篇关于AudioFlinger不能创造纪录的轨道,状态:-1,需要帮助IFX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 14:59