I am trying to implement simple logic to start / stop recording using MediaRecorderAndroid.
Cycle
- connect to localSocket / set options / mRecorder.prepare ();
- mRecorder.start ();
- mRecorder.stop (); mRecorder.reset ();
Then, loop between 2 and 3.
In the first cycle, 1,2,3 works fine, as expected, however, I have an error in the second start (reboot) after the first stop.
com.example.app E/MediaRecorder﹕ start called in an invalid state: 1
What is MediaRecorder state 1? What am I missing? Thanks for your input.
if (cmd.equals("connect"))
{
try
{
sender.connect(new LocalSocketAddress(SOCKET_ADDRESS));
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.AAC_ADTS);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
mRecorder.setOutputFile(sender.getFileDescriptor());
mRecorder.prepare();
}
catch (IOException e)
{ e.printStackTrace(); }
}
if (cmd.equals("start"))
{
try
{
mRecorder.start();
}
catch (IllegalStateException e)
{ e.printStackTrace(); }
}
if (cmd.equals("stop"))
{
try
{
mRecorder.stop();
mRecorder.reset();
}
catch (Exception e)
{ e.printStackTrace(); }
}
source
share