Attempting to record mic input over Bluetooth

397 views Asked by At

I have an Arduino which broadcasts via Bluetooth, input from a mic.

I want to connect the phone so that it'll record and save the input from the Arduino mic via Bluetooth.

When I run the following code, I have a few issues.

  1. I can't seem to find the file I saved.

    File file=new File(mFilePath2,"test.txt");
    
  2. On Logcat I'm getting the following errors when I run Bluetooth_Test()

    ACDB-LOADER   -    Error: ACDB AudProc vol returned = -19  
    
    MediaPlayer   -    Error (1, -1004)
    
  3. When I run stop() I get:

    MPEG4Writer   -    Stop() called but track is not started
    
    MediaPlayer-JNI    QCMediaPlayer mediaplayer NOT present
    
    MediaPlayer   -    Should have subtitle controller already set
    

I'm not sure what is happening and I'm not sure how to figure it out.

References:

Code:

    public void Bluetooth_Test (){

        Toast.makeText(getActivity(), "weee", Toast.LENGTH_LONG).show();

        maudioManager = (AudioManager) getActivity().getSystemService(getActivity().AUDIO_SERVICE);
        // Switch to headset
        maudioManager.setMode(AudioManager.MODE_IN_CALL); // to use headset's I/O and not phone's

        // Start audio I/O operation (in background)
        maudioManager.startBluetoothSco();

        mRecorder = new MediaRecorder();
        mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); // set source to current mic (should be Bluetooth)

        mFilePath = Environment.getExternalStorageDirectory().getAbsolutePath();
        String mFilePath2 = mFilePath;
        mFilePath += "/youraudiofile.mp3";
        File file=new File(mFilePath2,"test.txt");

        // Set file extension for the recorded audio file
        mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
        // Set a file path for the recorded audio file
        mRecorder.setOutputFile(mFilePath);
        // Set encoding of the audio
        mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
        try {
            mRecorder.prepare();
        }
        catch (IOException e){
            Log.e("Starting mRecorder", "IO Exception");
        }
        // Start recording
        mRecorder.start();

    }

  public void stop () {
        mRecorder.stop();
        mRecorder.reset();
        mRecorder.release();
        mRecorder = null;

        final MediaPlayer mPlayer = new MediaPlayer();
        try {
            mPlayer.setDataSource(mFilePath);
            mPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                                          @Override
                                          public void onPrepared(MediaPlayer mp) {
                                          mPlayer.start();            // Start playing audio file
                                          }
                                      });

                // Audio file to be played
                mPlayer.prepareAsync();
        } catch (IOException e){
            Log.e("Stop Function", "IO Exception");
        }           
    }
0

There are 0 answers