diff options
author | Jean-Michel Trivi <jmtrivi@google.com> | 2009-10-05 12:58:37 -0700 |
---|---|---|
committer | Jean-Michel Trivi <jmtrivi@google.com> | 2009-10-06 09:17:46 -0700 |
commit | 615384c62e2906613590e6f33a37f7dfe4276a59 (patch) | |
tree | 272db6e6fd98ab38ef688da0bc57e3c37b74339b | |
parent | 560d8a7070e976ec7a51775b1940599a26447bd0 (diff) | |
download | SoundRecorder-615384c62e2906613590e6f33a37f7dfe4276a59.tar.gz |
Fix bug 2157484 where SoundRecorder can crash when trying to record during a call.
On some platforms, you cannot be in a phone call and record audio
at the same time. In such a situation, the MediaRecorder throws a Runtime
exception. This CL catches this exception and checks whether a call
is underway or not. If it is, it will display an alert to the user
indicating recording cannot be performed during a call.
-rw-r--r-- | src/com/android/soundrecorder/Recorder.java | 23 | ||||
-rw-r--r-- | src/com/android/soundrecorder/SoundRecorder.java | 8 |
2 files changed, 26 insertions, 5 deletions
diff --git a/src/com/android/soundrecorder/Recorder.java b/src/com/android/soundrecorder/Recorder.java index 5fe41b0..cc24741 100644 --- a/src/com/android/soundrecorder/Recorder.java +++ b/src/com/android/soundrecorder/Recorder.java @@ -3,6 +3,8 @@ package com.android.soundrecorder; import java.io.File; import java.io.IOException; +import android.content.Context; +import android.media.AudioManager; import android.media.MediaPlayer; import android.media.MediaRecorder; import android.media.MediaPlayer.OnCompletionListener; @@ -25,6 +27,7 @@ public class Recorder implements OnCompletionListener, OnErrorListener { public static final int NO_ERROR = 0; public static final int SDCARD_ACCESS_ERROR = 1; public static final int INTERNAL_ERROR = 2; + public static final int IN_CALL_RECORD_ERROR = 3; public interface OnStateChangedListener { public void onStateChanged(int state); @@ -124,7 +127,7 @@ public class Recorder implements OnCompletionListener, OnErrorListener { signalStateChanged(IDLE_STATE); } - public void startRecording(int outputfileformat, String extension) { + public void startRecording(int outputfileformat, String extension, Context context) { stop(); if (mSampleFile == null) { @@ -156,8 +159,22 @@ public class Recorder implements OnCompletionListener, OnErrorListener { mRecorder = null; return; } - mRecorder.start(); - + // Handle RuntimeException if the recording couldn't start + try { + mRecorder.start(); + } catch (RuntimeException exception) { + AudioManager audioMngr = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE); + boolean isInCall = audioMngr.getMode() == AudioManager.MODE_IN_CALL; + if (isInCall) { + setError(IN_CALL_RECORD_ERROR); + } else { + setError(INTERNAL_ERROR); + } + mRecorder.reset(); + mRecorder.release(); + mRecorder = null; + return; + } mSampleStart = System.currentTimeMillis(); setState(RECORDING_STATE); } diff --git a/src/com/android/soundrecorder/SoundRecorder.java b/src/com/android/soundrecorder/SoundRecorder.java index ebafcb8..dbcb422 100644 --- a/src/com/android/soundrecorder/SoundRecorder.java +++ b/src/com/android/soundrecorder/SoundRecorder.java @@ -367,10 +367,11 @@ public class SoundRecorder extends Activity if (AUDIO_AMR.equals(mRequestedType)) { mRemainingTimeCalculator.setBitRate(BITRATE_AMR); - mRecorder.startRecording(MediaRecorder.OutputFormat.AMR_NB, ".amr"); + mRecorder.startRecording(MediaRecorder.OutputFormat.AMR_NB, ".amr", this); } else if (AUDIO_3GPP.equals(mRequestedType)) { mRemainingTimeCalculator.setBitRate(BITRATE_3GPP); - mRecorder.startRecording(MediaRecorder.OutputFormat.THREE_GPP, ".3gpp"); + mRecorder.startRecording(MediaRecorder.OutputFormat.THREE_GPP, ".3gpp", + this); } else { throw new IllegalArgumentException("Invalid output file type requested"); } @@ -829,6 +830,9 @@ public class SoundRecorder extends Activity case Recorder.SDCARD_ACCESS_ERROR: message = res.getString(R.string.error_sdcard_access); break; + case Recorder.IN_CALL_RECORD_ERROR: + // TODO: update error message to reflect that the recording could not be + // performed during a call. case Recorder.INTERNAL_ERROR: message = res.getString(R.string.error_app_internal); break; |