You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by al...@apache.org on 2016/08/15 09:49:15 UTC

cordova-plugin-media git commit: CB-11655 (Android) Enabled asynchronous error handling

Repository: cordova-plugin-media
Updated Branches:
  refs/heads/master 17fc9f3dd -> ae8b3567d


CB-11655 (Android) Enabled asynchronous error handling


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/commit/ae8b3567
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/tree/ae8b3567
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/diff/ae8b3567

Branch: refs/heads/master
Commit: ae8b3567d2400ad6398ff11df2dc600585919e60
Parents: 17fc9f3
Author: Alexander Sorokin <al...@akvelon.com>
Authored: Fri Aug 12 18:37:23 2016 +0300
Committer: Alexander Sorokin <al...@akvelon.com>
Committed: Mon Aug 15 12:20:28 2016 +0300

----------------------------------------------------------------------
 src/android/AudioPlayer.java | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/blob/ae8b3567/src/android/AudioPlayer.java
----------------------------------------------------------------------
diff --git a/src/android/AudioPlayer.java b/src/android/AudioPlayer.java
index 25a2421..3392f2e 100644
--- a/src/android/AudioPlayer.java
+++ b/src/android/AudioPlayer.java
@@ -102,7 +102,6 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
         this.handler = handler;
         this.id = id;
         this.audioFile = file;
-        this.recorder = new MediaRecorder();
         this.tempFiles = new LinkedList<String>();
     }
 
@@ -149,6 +148,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
             break;
         case NONE:
             this.audioFile = file;
+            this.recorder = new MediaRecorder();
             this.recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
             this.recorder.setOutputFormat(MediaRecorder.OutputFormat.RAW_AMR); // THREE_GPP);
             this.recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); //AMR_NB);
@@ -472,12 +472,13 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
     public boolean onError(MediaPlayer player, int arg1, int arg2) {
         Log.d(LOG_TAG, "AudioPlayer.onError(" + arg1 + ", " + arg2 + ")");
 
-        // TODO: Not sure if this needs to be sent?
-        this.player.stop();
-        this.player.release();
-
+        // we don't want to send success callback
+        // so we don't call setState() here
+        this.state = STATE.MEDIA_STOPPED;
+        this.destroy();
         // Send error notification to JavaScript
         sendErrorStatus(arg1);
+
         return false;
     }
 
@@ -554,6 +555,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
                 case MEDIA_NONE:
                     if (this.player == null) {
                         this.player = new MediaPlayer();
+                        this.player.setOnErrorListener(this);
                     }
                     try {
                         this.loadAudioFile(file);
@@ -576,6 +578,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
                         //maybe it was recording?
                         if(this.recorder!=null && player==null) {
                             this.player = new MediaPlayer();
+                            this.player.setOnErrorListener(this);
                             this.prepareOnly = false;
 
                             try {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org