incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From macdo...@apache.org
Subject [2/2] android commit: CB-1267: Reuse Media object for recording
Date Mon, 20 Aug 2012 20:24:39 GMT
CB-1267: Reuse Media object for recording


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/commit/afe504db
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/tree/afe504db
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/diff/afe504db

Branch: refs/heads/master
Commit: afe504dbbfe57a7f0f02df6342f24c9b57e27762
Parents: 8d0e806
Author: macdonst <simon.macdonald@gmail.com>
Authored: Mon Aug 20 16:23:19 2012 -0400
Committer: macdonst <simon.macdonald@gmail.com>
Committed: Mon Aug 20 16:23:19 2012 -0400

----------------------------------------------------------------------
 framework/src/org/apache/cordova/AudioHandler.java |    2 +-
 framework/src/org/apache/cordova/AudioPlayer.java  |   36 +++++++--------
 2 files changed, 18 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/afe504db/framework/src/org/apache/cordova/AudioHandler.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/AudioHandler.java b/framework/src/org/apache/cordova/AudioHandler.java
index f9368d4..3f8d2e8 100644
--- a/framework/src/org/apache/cordova/AudioHandler.java
+++ b/framework/src/org/apache/cordova/AudioHandler.java
@@ -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);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/afe504db/framework/src/org/apache/cordova/AudioPlayer.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/AudioPlayer.java b/framework/src/org/apache/cordova/AudioPlayer.java
index 6fbb8cc..90e0e16 100644
--- a/framework/src/org/apache/cordova/AudioPlayer.java
+++ b/framework/src/org/apache/cordova/AudioPlayer.java
@@ -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,26 +138,22 @@ 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);
-                this.recorder.setOutputFile(this.tempFile);
-                try {
-                    this.recorder.prepare();
-                    this.recorder.start();
-                    this.setState(STATE.MEDIA_RUNNING);
-                    return;
-                } catch (IllegalStateException e) {
-                    e.printStackTrace();
-                } catch (IOException e) {
-                    e.printStackTrace();
-                }
-                this.handler.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('"
+ this.id + "', "+MEDIA_ERROR+", { \"code\":"+MEDIA_ERR_ABORTED+"});");
+            this.audioFile = file;
+            this.recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
+            this.recorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT); // THREE_GPP);
+            this.recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT); //AMR_NB);
+            this.recorder.setOutputFile(this.tempFile);
+            try {
+                this.recorder.prepare();
+                this.recorder.start();
+                this.setState(STATE.MEDIA_RUNNING);
+                return;
+            } catch (IllegalStateException e) {
+                e.printStackTrace();
+            } catch (IOException e) {
+                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) {


Mime
View raw message