MediaRecorder on Android interfeering with other Media Aplications

522 views Asked by At

I am using the MediaRecorder in my app to measure decibel. For this a new MediaRecorder-Object is created once every 10 seconds, it runs for one second during which getMaxAmplitude() is called 10 times and the average is calculated. After this the MediaRecorder object is stopped and deleted.

The Method to start the Recorder looks like this

public boolean start()
{
   mRecorder = new MediaRecorder();
     mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
     mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
     mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); 
     mRecorder.setOutputFile("/dev/null");
     try 
     {
        mRecorder.prepare();
     } 
     catch (IllegalStateException e) 
     {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return false;
     } 
     catch (IOException e) 
     {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return false;
     }
     catch(Exception e)
     {
        e.printStackTrace();
        return false;
     }
     mRecorder.start();
     mRecorder.getMaxAmplitude();
     return true;

}

and the Method to stop looks like this

public void stop() 
{
    //Log.d("SPLService", "stop()");
    mRecorder.stop();
    mRecorder.reset();
    mRecorder.release();
    mRecorder=null;

}

This is pretty much the way the tutorial on the Android Website instructed.

The problem arises when I use this app in parallel with other Apps using Media, like the Mediaplayer on Android. Whenever a sound measurement is taken using my App other media Apps stop or even crash, even though their objects should be independent of mine.

I have tried using AudioRecord instead of MediaRecorder but the interference with other apps was the same.

I guess my question would be: how can I avoid such interference?

0

There are 0 answers