Methods Summary |
---|
public void | clear()Resets the recorder state. If a sample was recorded, the file is left on disk and will
be reused for a new recording.
stop();
mSampleLength = 0;
signalStateChanged(IDLE_STATE);
|
public void | delete()Resets the recorder state. If a sample was recorded, the file is deleted.
stop();
if (mSampleFile != null)
mSampleFile.delete();
mSampleFile = null;
mSampleLength = 0;
signalStateChanged(IDLE_STATE);
|
public int | getMaxAmplitude()
if (mState != RECORDING_STATE)
return 0;
return mRecorder.getMaxAmplitude();
|
public void | onCompletion(android.media.MediaPlayer mp)
stop();
|
public boolean | onError(android.media.MediaPlayer mp, int what, int extra)
stop();
setError(SDCARD_ACCESS_ERROR);
return true;
|
public int | progress()
if (mState == RECORDING_STATE || mState == PLAYING_STATE)
return (int) ((System.currentTimeMillis() - mSampleStart)/1000);
return 0;
|
public void | restoreState(android.os.Bundle recorderState)
String samplePath = recorderState.getString(SAMPLE_PATH_KEY);
if (samplePath == null)
return;
int sampleLength = recorderState.getInt(SAMPLE_LENGTH_KEY, -1);
if (sampleLength == -1)
return;
File file = new File(samplePath);
if (!file.exists())
return;
if (mSampleFile != null
&& mSampleFile.getAbsolutePath().compareTo(file.getAbsolutePath()) == 0)
return;
delete();
mSampleFile = file;
mSampleLength = sampleLength;
signalStateChanged(IDLE_STATE);
|
public java.io.File | sampleFile()
return mSampleFile;
|
public int | sampleLength()
return mSampleLength;
|
public void | saveState(android.os.Bundle recorderState)
recorderState.putString(SAMPLE_PATH_KEY, mSampleFile.getAbsolutePath());
recorderState.putInt(SAMPLE_LENGTH_KEY, mSampleLength);
|
private void | setError(int error)
if (mOnStateChangedListener != null)
mOnStateChangedListener.onError(error);
|
public void | setOnStateChangedListener(com.android.soundrecorder.Recorder$OnStateChangedListener listener)
mOnStateChangedListener = listener;
|
private void | setState(int state)
if (state == mState)
return;
mState = state;
signalStateChanged(mState);
|
private void | signalStateChanged(int state)
if (mOnStateChangedListener != null)
mOnStateChangedListener.onStateChanged(state);
|
public void | startPlayback()
stop();
mPlayer = new MediaPlayer();
try {
mPlayer.setDataSource(mSampleFile.getAbsolutePath());
mPlayer.setOnCompletionListener(this);
mPlayer.setOnErrorListener(this);
mPlayer.prepare();
mPlayer.start();
} catch (IllegalArgumentException e) {
setError(INTERNAL_ERROR);
mPlayer = null;
return;
} catch (IOException e) {
setError(SDCARD_ACCESS_ERROR);
mPlayer = null;
return;
}
mSampleStart = System.currentTimeMillis();
setState(PLAYING_STATE);
|
public void | startRecording(int outputfileformat, java.lang.String extension)
stop();
if (mSampleFile == null) {
File sampleDir = Environment.getExternalStorageDirectory();
if (!sampleDir.canWrite()) // Workaround for broken sdcard support on the device.
sampleDir = new File("/sdcard/sdcard");
try {
mSampleFile = File.createTempFile(SAMPLE_PREFIX, extension, sampleDir);
} catch (IOException e) {
setError(SDCARD_ACCESS_ERROR);
return;
}
}
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(outputfileformat);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mRecorder.setOutputFile(mSampleFile.getAbsolutePath());
// Handle IOException
try {
mRecorder.prepare();
} catch(IOException exception) {
setError(INTERNAL_ERROR);
mRecorder.reset();
mRecorder.release();
mRecorder = null;
return;
}
mRecorder.start();
mSampleStart = System.currentTimeMillis();
setState(RECORDING_STATE);
|
public int | state()
return mState;
|
public void | stop()
stopRecording();
stopPlayback();
|
public void | stopPlayback()
if (mPlayer == null) // we were not in playback
return;
mPlayer.stop();
mPlayer.release();
mPlayer = null;
setState(IDLE_STATE);
|
public void | stopRecording()
if (mRecorder == null)
return;
mRecorder.stop();
mRecorder.release();
mRecorder = null;
mSampleLength = (int)( (System.currentTimeMillis() - mSampleStart)/1000 );
setState(IDLE_STATE);
|