4

Brief: How to check if voice recording is already running in background in some other app.

Detail: if voice recording is already running in background from native app: Voice recorder. Now I have implemented voice recording as one of feature in my application.

Problem: when i try recording in my app at the same time, it gives error :

  : E/MediaRecorder: start failed: -38
  : E/MyApp: [1162][com.sec.MyApp.multimedia.RecordMyVoice]java.lang.IllegalStateException
  : E/MyApp:    at android.media.MediaRecorder.start(Native Method)
  : E/MyApp:    at com.sec.MyApp.multimedia.RecordMyVoice.doInBackground(RecordMyVoice.java:100)

Code at 100th line in RecordMyVoice.java:

    mRecorder = new MediaRecorder();
    mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    mRecorder.setOutputFile(mFileName);
    mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
    mRecorder.prepare();
    mRecorder.start(); //code at 100th line

But problem is because already voice recording is running in background. Therefore is there any way to stop voice recording if its running in some other app.

Any input would be of great help.

Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
parul
  • 363
  • 1
  • 6
  • 16
  • If it is already running, then it should have a reason, doesn't it? You could prompt the user to stop it if he wants to use _your_ recording feature. Not really a satisfying answer, therefore only a comment. Maybe somebody has a better idea. – Fildor Oct 01 '12 at 14:28
  • You should at least catch the exceptions thrown by `prepare` and `start`. – Michael Oct 01 '12 at 14:42
  • I have added try catch block, but still handler returns error msg and there i'm displaying toast as failed to record. But i want the background recorder to be stopped. – parul Oct 02 '12 at 16:27
  • @Parul Is it solved now ? – TheLittleNaruto Feb 05 '14 at 14:04
  • Can you show the string of mFileName. I think there is problem in your mFileName. – Vikrant_Dev May 20 '14 at 05:09

2 Answers2

1

i've had the same Error -38, i found out that there is Another background service that uses the mic via (AudioRecord), when disabling the background service , it worked.

Robocide
  • 6,353
  • 4
  • 37
  • 41
0

Check your file path, the directory must be existed.

tuoxie007
  • 1,234
  • 12
  • 10