android - MediaRecorder throws illegalstateexception

Ich versuche zu entwickeln, die eine einfache android-audio-recorder.Alles baut gut und es läuft auch problemlos auf dem android-Gerät. Wie es scheint, kann ich die Aufnahme starten aber wenn ich aufhören wollen, es wirft eine IllegalStateException. Ich kann nicht finden den Fehler. Hier ist der code:

public class VoiceRecorder {
MediaRecorder recorder= new MediaRecorder();
static Context cont;

public void startRecord(Context context) throws IllegalStateException, IOException{
    cont = context;

    recorder.setAudioSource(MediaRecorder.AudioSource.MIC); 
    recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); 
    recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); 
    recorder.setOutputFile(cont.getFilesDir()+"/recordings.3gp"); 
    recorder.prepare();
    recorder.start();  

 }  
public void stopRecording(Context context) {
    cont = context;
    recorder.stop();
    recorder.release();
    File file = new File (cont.getFilesDir()+"/recordings.3gp");
    UploadFile.uploadFile("recordings.3gp", file);
    recorder = null;
 }
}

Möchte ich, um es zu lösen mit:

VoiceRecorder vr = new VoiceRecorder();

vr.startRecord(cont);

vr.stopRecording(cont);

beim Aufruf von start Logcat sagt: (was soll ok sein)

09-06 22:56:42.830: D/AudioHardwareMSM72XX(123): audpre_index = 0, tx_iir_index = 0
09-06 22:56:42.840: D/HTC Acoustic(123): msm72xx_enable_audpre: 0x0000
09-06 22:56:42.850: I/AudioHardwareMSM72XX(123): Routing audio to Speakerphone
09-06 22:56:42.850: D/HTC Acoustic(123): msm72xx_enable_audpp: 0x0001
09-06 22:56:42.850: I/AudioHardwareMSM72XX(123): Routing audio to Speakerphone
09-06 22:56:42.860: D/HTC Acoustic(123): msm72xx_enable_audpp: 0x0001
09-06 22:56:42.870: D/AudioFlinger(123): setParameters(): io 3, keyvalue routing=262144;vr_mode=0, tid 156, calling tid 123
09-06 22:56:42.870: I/AudioHardwareMSM72XX(123): Routing audio to Speakerphone
09-06 22:56:42.880: D/AudioHardwareMSM72XX(123): audpre_index = 0, tx_iir_index = 0
09-06 22:56:42.880: D/HTC Acoustic(123): msm72xx_enable_audpre: 0x0000
09-06 22:56:42.880: I/AudioHardwareMSM72XX(123): do input routing device 40000
09-06 22:56:42.880: I/AudioHardwareMSM72XX(123): Routing audio to Speakerphone
09-06 22:56:42.890: D/HTC Acoustic(123): msm72xx_enable_audpp: 0x0001

Aber wenn ich stop rufen:

09-06 22:59:52.440: E/MediaRecorder(1069): stop called in an invalid state: 1
09-06 22:59:52.440: W/System.err(1069): java.lang.IllegalStateException
09-06 22:59:52.460: W/System.err(1069):     at android.media.MediaRecorder.stop(Native Method)
09-06 22:59:52.460: W/System.err(1069):     at de.spyapp.VoiceRecorder.stopRecording(VoiceRecorder.java:33)
09-06 22:59:52.460: W/System.err(1069):     at de.spyapp.CheckCMD.checkCMD(CheckCMD.java:30)
09-06 22:59:52.460: W/System.err(1069):     at de.spyapp.AppActivity$2.run(AppActivity.java:44)
09-06 22:59:52.460: W/System.err(1069):     at java.lang.Thread.run(Thread.java:1096)

InformationsquelleAutor Dominik Trenz | 2012-09-06

Schreibe einen Kommentar