Loading plugin.xml +4 −1 Changes for plugin.xml: 4 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -17,12 +17,15 @@ id="org.apache.cordova.core.AudioHandler" <!-- android --> <platform name="android"> <config-file target="res/xml/config.xml" parent="/*"> <plugin name="Media" value="org.apache.cordova.core.AudioHandler"/> <feature name="Media" > <param name="android-package" value="org.apache.cordova.core.AudioHandler"/> </feature> </config-file> <config-file target="AndroidManifest.xml" parent="/*"> <uses-permission android:name="android.permission.RECORD_AUDIO" /> <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> </config-file> <source-file src="src/android/AudioHandler.java" target-dir="src/org/apache/cordova/core" /> Loading src/android/AudioPlayer.java +16 −15 Changes for src/android/AudioPlayer.java: 16 added lines, 15 removed lines. Original line number Diff line number Diff line Loading @@ -133,7 +133,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On switch (this.mode) { case PLAY: Log.d(LOG_TAG, "AudioPlayer Error: Can't record in play mode."); this.handler.webView.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", { \"code\":"+MEDIA_ERR_ABORTED+"});"); this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.core.AudioHandler.Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", { \"code\":"+MEDIA_ERR_ABORTED+"});"); break; case NONE: this.audioFile = file; Loading @@ -151,11 +151,12 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On } catch (IOException e) { e.printStackTrace(); } this.handler.webView.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", { \"code\":"+MEDIA_ERR_ABORTED+"});"); this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.core.AudioHandler.Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", { \"code\":"+MEDIA_ERR_ABORTED+"});"); break; case RECORD: Log.d(LOG_TAG, "AudioPlayer Error: Already recording."); this.handler.webView.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", { \"code\":"+MEDIA_ERR_ABORTED+"});"); this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.core.AudioHandler.Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", { \"code\":"+MEDIA_ERR_ABORTED+"});"); } } Loading Loading @@ -226,7 +227,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On if (this.readyPlayer(this.audioFile)) { this.player.seekTo(milliseconds); Log.d(LOG_TAG, "Send a onStatus update for the new seek"); this.handler.webView.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', " + MEDIA_POSITION + ", " + milliseconds / 1000.0f + ");"); this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.core.AudioHandler.Media').onStatus('" + this.id + "', " + MEDIA_POSITION + ", " + milliseconds / 1000.0f + ");"); } else { this.seekOnPrepared = milliseconds; Loading @@ -245,7 +246,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On } else { Log.d(LOG_TAG, "AudioPlayer Error: pausePlaying() called during invalid state: " + this.state.ordinal()); this.handler.webView.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', " + MEDIA_ERROR + ", { \"code\":" + MEDIA_ERR_NONE_ACTIVE + "});"); this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.core.AudioHandler.Media').onStatus('" + this.id + "', " + MEDIA_ERROR + ", { \"code\":" + MEDIA_ERR_NONE_ACTIVE + "});"); } } Loading @@ -261,7 +262,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On } else { Log.d(LOG_TAG, "AudioPlayer Error: stopPlaying() called during invalid state: " + this.state.ordinal()); this.handler.webView.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', " + MEDIA_ERROR + ", { \"code\":" + MEDIA_ERR_NONE_ACTIVE + "});"); this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.core.AudioHandler.Media').onStatus('" + this.id + "', " + MEDIA_ERROR + ", { \"code\":" + MEDIA_ERR_NONE_ACTIVE + "});"); } } Loading @@ -283,7 +284,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On public long getCurrentPosition() { if ((this.state == STATE.MEDIA_RUNNING) || (this.state == STATE.MEDIA_PAUSED)) { int curPos = this.player.getCurrentPosition(); this.handler.webView.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', " + MEDIA_POSITION + ", " + curPos / 1000.0f + ");"); this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.core.AudioHandler.Media').onStatus('" + this.id + "', " + MEDIA_POSITION + ", " + curPos / 1000.0f + ");"); return curPos; } else { Loading Loading @@ -362,7 +363,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On this.prepareOnly = true; // Send status notification to JavaScript this.handler.webView.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', " + MEDIA_DURATION + "," + this.duration + ");"); this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.core.AudioHandler.Media').onStatus('" + this.id + "', " + MEDIA_DURATION + "," + this.duration + ");"); } /** Loading Loading @@ -390,7 +391,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On this.player.release(); // Send error notification to JavaScript this.handler.webView.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', { \"code\":" + arg1 + "});"); this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.core.AudioHandler.Media').onStatus('" + this.id + "', { \"code\":" + arg1 + "});"); return false; } Loading @@ -401,7 +402,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On */ private void setState(STATE state) { if (this.state != state) { this.handler.webView.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', " + MEDIA_STATE + ", " + state.ordinal() + ");"); this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.core.AudioHandler.Media').onStatus('" + this.id + "', " + MEDIA_STATE + ", " + state.ordinal() + ");"); } this.state = state; } Loading @@ -414,7 +415,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On private void setMode(MODE mode) { if (this.mode != mode) { //mode is not part of the expected behavior, so no notification //this.handler.webView.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', " + MEDIA_STATE + ", " + mode + ");"); //this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.core.AudioHandler.Media').onStatus('" + this.id + "', " + MEDIA_STATE + ", " + mode + ");"); } this.mode = mode; } Loading Loading @@ -450,7 +451,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On break; case RECORD: Log.d(LOG_TAG, "AudioPlayer Error: Can't play in record mode."); this.handler.webView.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', " + MEDIA_ERROR + ", { \"code\":" + MEDIA_ERR_ABORTED + "});"); this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.core.AudioHandler.Media').onStatus('" + this.id + "', " + MEDIA_ERROR + ", { \"code\":" + MEDIA_ERR_ABORTED + "});"); return false; //player is not ready } return true; Loading @@ -471,7 +472,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On try { this.loadAudioFile(file); } catch (Exception e) { this.handler.webView.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", { \"code\":"+MEDIA_ERR_ABORTED+"});"); this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.core.AudioHandler.Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", { \"code\":"+MEDIA_ERR_ABORTED+"});"); } return false; case MEDIA_LOADING: Loading @@ -496,14 +497,14 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On try { this.loadAudioFile(file); } catch (Exception e) { this.handler.webView.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', " + MEDIA_ERROR + ", { \"code\":" + MEDIA_ERR_ABORTED + "});"); this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.core.AudioHandler.Media').onStatus('" + this.id + "', " + MEDIA_ERROR + ", { \"code\":" + MEDIA_ERR_ABORTED + "});"); } //if we had to prepare= the file, we won't be in the correct state for playback return false; } default: Log.d(LOG_TAG, "AudioPlayer Error: startPlaying() called during invalid state: " + this.state); this.handler.webView.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', " + MEDIA_ERROR + ", { \"code\":" + MEDIA_ERR_ABORTED + "});"); this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.core.AudioHandler.Media').onStatus('" + this.id + "', " + MEDIA_ERROR + ", { \"code\":" + MEDIA_ERR_ABORTED + "});"); } } return false; Loading Loading
plugin.xml +4 −1 Changes for plugin.xml: 4 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -17,12 +17,15 @@ id="org.apache.cordova.core.AudioHandler" <!-- android --> <platform name="android"> <config-file target="res/xml/config.xml" parent="/*"> <plugin name="Media" value="org.apache.cordova.core.AudioHandler"/> <feature name="Media" > <param name="android-package" value="org.apache.cordova.core.AudioHandler"/> </feature> </config-file> <config-file target="AndroidManifest.xml" parent="/*"> <uses-permission android:name="android.permission.RECORD_AUDIO" /> <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> </config-file> <source-file src="src/android/AudioHandler.java" target-dir="src/org/apache/cordova/core" /> Loading
src/android/AudioPlayer.java +16 −15 Changes for src/android/AudioPlayer.java: 16 added lines, 15 removed lines. Original line number Diff line number Diff line Loading @@ -133,7 +133,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On switch (this.mode) { case PLAY: Log.d(LOG_TAG, "AudioPlayer Error: Can't record in play mode."); this.handler.webView.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", { \"code\":"+MEDIA_ERR_ABORTED+"});"); this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.core.AudioHandler.Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", { \"code\":"+MEDIA_ERR_ABORTED+"});"); break; case NONE: this.audioFile = file; Loading @@ -151,11 +151,12 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On } catch (IOException e) { e.printStackTrace(); } this.handler.webView.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", { \"code\":"+MEDIA_ERR_ABORTED+"});"); this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.core.AudioHandler.Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", { \"code\":"+MEDIA_ERR_ABORTED+"});"); break; case RECORD: Log.d(LOG_TAG, "AudioPlayer Error: Already recording."); this.handler.webView.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", { \"code\":"+MEDIA_ERR_ABORTED+"});"); this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.core.AudioHandler.Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", { \"code\":"+MEDIA_ERR_ABORTED+"});"); } } Loading Loading @@ -226,7 +227,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On if (this.readyPlayer(this.audioFile)) { this.player.seekTo(milliseconds); Log.d(LOG_TAG, "Send a onStatus update for the new seek"); this.handler.webView.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', " + MEDIA_POSITION + ", " + milliseconds / 1000.0f + ");"); this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.core.AudioHandler.Media').onStatus('" + this.id + "', " + MEDIA_POSITION + ", " + milliseconds / 1000.0f + ");"); } else { this.seekOnPrepared = milliseconds; Loading @@ -245,7 +246,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On } else { Log.d(LOG_TAG, "AudioPlayer Error: pausePlaying() called during invalid state: " + this.state.ordinal()); this.handler.webView.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', " + MEDIA_ERROR + ", { \"code\":" + MEDIA_ERR_NONE_ACTIVE + "});"); this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.core.AudioHandler.Media').onStatus('" + this.id + "', " + MEDIA_ERROR + ", { \"code\":" + MEDIA_ERR_NONE_ACTIVE + "});"); } } Loading @@ -261,7 +262,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On } else { Log.d(LOG_TAG, "AudioPlayer Error: stopPlaying() called during invalid state: " + this.state.ordinal()); this.handler.webView.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', " + MEDIA_ERROR + ", { \"code\":" + MEDIA_ERR_NONE_ACTIVE + "});"); this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.core.AudioHandler.Media').onStatus('" + this.id + "', " + MEDIA_ERROR + ", { \"code\":" + MEDIA_ERR_NONE_ACTIVE + "});"); } } Loading @@ -283,7 +284,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On public long getCurrentPosition() { if ((this.state == STATE.MEDIA_RUNNING) || (this.state == STATE.MEDIA_PAUSED)) { int curPos = this.player.getCurrentPosition(); this.handler.webView.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', " + MEDIA_POSITION + ", " + curPos / 1000.0f + ");"); this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.core.AudioHandler.Media').onStatus('" + this.id + "', " + MEDIA_POSITION + ", " + curPos / 1000.0f + ");"); return curPos; } else { Loading Loading @@ -362,7 +363,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On this.prepareOnly = true; // Send status notification to JavaScript this.handler.webView.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', " + MEDIA_DURATION + "," + this.duration + ");"); this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.core.AudioHandler.Media').onStatus('" + this.id + "', " + MEDIA_DURATION + "," + this.duration + ");"); } /** Loading Loading @@ -390,7 +391,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On this.player.release(); // Send error notification to JavaScript this.handler.webView.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', { \"code\":" + arg1 + "});"); this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.core.AudioHandler.Media').onStatus('" + this.id + "', { \"code\":" + arg1 + "});"); return false; } Loading @@ -401,7 +402,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On */ private void setState(STATE state) { if (this.state != state) { this.handler.webView.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', " + MEDIA_STATE + ", " + state.ordinal() + ");"); this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.core.AudioHandler.Media').onStatus('" + this.id + "', " + MEDIA_STATE + ", " + state.ordinal() + ");"); } this.state = state; } Loading @@ -414,7 +415,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On private void setMode(MODE mode) { if (this.mode != mode) { //mode is not part of the expected behavior, so no notification //this.handler.webView.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', " + MEDIA_STATE + ", " + mode + ");"); //this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.core.AudioHandler.Media').onStatus('" + this.id + "', " + MEDIA_STATE + ", " + mode + ");"); } this.mode = mode; } Loading Loading @@ -450,7 +451,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On break; case RECORD: Log.d(LOG_TAG, "AudioPlayer Error: Can't play in record mode."); this.handler.webView.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', " + MEDIA_ERROR + ", { \"code\":" + MEDIA_ERR_ABORTED + "});"); this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.core.AudioHandler.Media').onStatus('" + this.id + "', " + MEDIA_ERROR + ", { \"code\":" + MEDIA_ERR_ABORTED + "});"); return false; //player is not ready } return true; Loading @@ -471,7 +472,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On try { this.loadAudioFile(file); } catch (Exception e) { this.handler.webView.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", { \"code\":"+MEDIA_ERR_ABORTED+"});"); this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.core.AudioHandler.Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", { \"code\":"+MEDIA_ERR_ABORTED+"});"); } return false; case MEDIA_LOADING: Loading @@ -496,14 +497,14 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On try { this.loadAudioFile(file); } catch (Exception e) { this.handler.webView.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', " + MEDIA_ERROR + ", { \"code\":" + MEDIA_ERR_ABORTED + "});"); this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.core.AudioHandler.Media').onStatus('" + this.id + "', " + MEDIA_ERROR + ", { \"code\":" + MEDIA_ERR_ABORTED + "});"); } //if we had to prepare= the file, we won't be in the correct state for playback return false; } default: Log.d(LOG_TAG, "AudioPlayer Error: startPlaying() called during invalid state: " + this.state); this.handler.webView.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', " + MEDIA_ERROR + ", { \"code\":" + MEDIA_ERR_ABORTED + "});"); this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.core.AudioHandler.Media').onStatus('" + this.id + "', " + MEDIA_ERROR + ", { \"code\":" + MEDIA_ERR_ABORTED + "});"); } } return false; Loading