CB-1267: Reuse Media object for recording

This commit is contained in:
macdonst 2012-08-20 16:23:19 -04:00
parent 8d0e80620a
commit afe504dbbf
2 changed files with 18 additions and 20 deletions

View File

@ -20,6 +20,7 @@ package org.apache.cordova;
import android.content.Context;
import android.media.AudioManager;
import java.util.ArrayList;
import org.apache.cordova.api.Plugin;
@ -214,7 +215,6 @@ public class AudioHandler extends Plugin {
AudioPlayer audio = this.players.get(id);
if (audio != null) {
audio.stopRecording();
this.players.remove(id);
}
}

View File

@ -96,6 +96,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
this.handler = handler;
this.id = id;
this.audioFile = file;
this.recorder = new MediaRecorder();
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
this.tempFile = Environment.getExternalStorageDirectory().getAbsolutePath() + "/tmprecording.3gp";
@ -137,10 +138,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
this.handler.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", { \"code\":"+MEDIA_ERR_ABORTED+"});");
break;
case NONE:
// Make sure we're not already recording
if (this.recorder == null) {
this.audioFile = file;
this.recorder = new MediaRecorder();
this.recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
this.recorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT); // THREE_GPP);
this.recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT); //AMR_NB);
@ -156,7 +154,6 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
e.printStackTrace();
}
this.handler.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", { \"code\":"+MEDIA_ERR_ABORTED+"});");
}
break;
case RECORD:
Log.d(LOG_TAG, "AudioPlayer Error: Already recording.");
@ -191,6 +188,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
this.recorder.stop();
this.setState(STATE.MEDIA_STOPPED);
}
this.recorder.reset();
this.moveFile(this.audioFile);
}
catch (Exception e) {