1. Download our Official Android App: Forums for Android!

Apps AudioRecord error startPlaying() need help please...

Discussion in 'Android Development' started by kcon90, Jun 30, 2011.

  1. kcon90

    kcon90 Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    3
    Joined:
    Jun 16, 2011

    Jun 16, 2011
    3
    0
    5
    So im trying to make it so you can talk into the mic and have the output played at the same time, kind of like a microphone connected to a speaker. I have all the buffer stuff and all that figured out. My app still crashes and Log says I'm trying to call startRecording on an uninitialized AudioRecord. ​

    I don't understand because it is clearly initialized. Does anyone have any clue as to what is wrong????​

    Code (Text):
    1.  
    2. [LEFT]public void setRecorder() throws IllegalArgumentException
    3. {
    4. int minBuffer = AudioRecord.getMinBufferSize(sampleRate,
    5. AudioFormat.CHANNEL_IN_MONO,
    6. AudioFormat.ENCODING_PCM_16BIT);
    7. int bufferSize = minBuffer + 1000;[/LEFT]
    8.  
    9.  
    10. [LEFT][B]AudioRecord micr[/B] = new AudioRecord(MediaRecorder.AudioSource.MIC, sampleRate,
    11. AudioFormat.CHANNEL_IN_MONO,
    12. AudioFormat.ENCODING_PCM_16BIT,
    13. bufferSize);[/LEFT]
    14.  
    15. [LEFT]AudioTrack micp = new AudioTrack(AudioManager.STREAM_MUSIC,
    16. sampleRate,
    17. AudioFormat.CHANNEL_OUT_MONO,
    18. AudioFormat.ENCODING_PCM_16BIT,
    19. bufferSize,
    20. AudioTrack.MODE_STREAM);[/LEFT]
    21.  
    22. [LEFT]micp.setPlaybackRate(sampleRate);
    23. byte[] buffer = new byte[bufferSize];
    24. [B]micr.startRecording(); [/B]// THis is whats causing the error
    25. micp.play();
    26. while (isRecording)
    27. {
    28.     micr.read(buffer, 0, bufferSize);
    29.     micp.write(buffer, 0, bufferSize);
    30. }[/LEFT]
    31. }
    32.  
     

    Advertisement

Share This Page

Loading...