Commit 6de7e53f authored by Steven Gill's avatar Steven Gill
Browse files

Merge branch 'dev'

parents 29d8c381 9fdbb3ea
Loading
Loading
Loading
Loading
+13 −1
Changes for RELEASENOTES.md: 13 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -20,6 +20,18 @@
-->
# Release Notes


### 0.2.1 (Sept 5, 2013)
* CB-4432 copyright notice change

### 0.2.3 (Sept 25, 2013)
* CB-4889 bumping&resetting version
* [windows8] commandProxy was moved
* CB-4889 renaming references
* CB-4889 renaming org.apache.cordova.core.media to org.apache.cordova.media
* [CB-4847] iOS 7 microphone access requires user permission - if denied, CDVCapture, CDVSound does not handle it properly
* Rename CHANGELOG.md -> RELEASENOTES.md
* [CB-4799] Fix incorrect JS references within native code on Android & iOS
* Fix compiler/lint warnings
* Rename plugin id from AudioHandler -> media
* [CB-4763] Remove reference to cordova-android's FileHelper.
* [CB-4752] Incremented plugin version on dev branch.
+3 −2
Changes for plugin.xml: 3 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -2,8 +2,8 @@

<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="org.apache.cordova.core.AudioHandler"
    version="0.2.1">
id="org.apache.cordova.media"
    version="0.2.3">
    <name>Media</name>
    <description>Cordova Media Plugin</description>
    <license>Apache 2.0</license>
@@ -33,6 +33,7 @@ id="org.apache.cordova.core.AudioHandler"
        
        <source-file src="src/android/AudioHandler.java" target-dir="src/org/apache/cordova/media" />
        <source-file src="src/android/AudioPlayer.java" target-dir="src/org/apache/cordova/media" />
        <source-file src="src/android/FileHelper.java" target-dir="src/org/apache/cordova/media" />
     </platform>
     
     <!-- ios -->
+0 −1
Changes for src/android/AudioHandler.java: 0 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@
*/
package org.apache.cordova.media;

import org.apache.cordova.FileHelper;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;

+19 −19
Changes for src/android/AudioPlayer.java: 19 added lines, 19 removed lines.
Original line number Diff line number Diff line
@@ -65,9 +65,9 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
    // Media error codes
    private static int MEDIA_ERR_NONE_ACTIVE    = 0;
    private static int MEDIA_ERR_ABORTED        = 1;
    private static int MEDIA_ERR_NETWORK        = 2;
    private static int MEDIA_ERR_DECODE         = 3;
    private static int MEDIA_ERR_NONE_SUPPORTED = 4;
//    private static int MEDIA_ERR_NETWORK        = 2;
//    private static int MEDIA_ERR_DECODE         = 3;
//    private static int MEDIA_ERR_NONE_SUPPORTED = 4;

    private AudioHandler handler;           // The AudioHandler object
    private String id;                      // The id of this player (used to identify Media object in JavaScript)
@@ -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('org.apache.cordova.core.AudioHandler.Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", { \"code\":"+MEDIA_ERR_ABORTED+"});");
            this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.media.Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", { \"code\":"+MEDIA_ERR_ABORTED+"});");
            break;
        case NONE:
            this.audioFile = file;
@@ -152,11 +152,11 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
                e.printStackTrace();
            }

            this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.core.AudioHandler.Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", { \"code\":"+MEDIA_ERR_ABORTED+"});");
            this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.media.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('org.apache.cordova.core.AudioHandler.Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", { \"code\":"+MEDIA_ERR_ABORTED+"});");
            this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.media.Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", { \"code\":"+MEDIA_ERR_ABORTED+"});");
        }
    }

@@ -227,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('org.apache.cordova.core.AudioHandler.Media').onStatus('" + this.id + "', " + MEDIA_POSITION + ", " + milliseconds / 1000.0f + ");");
            this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.media.Media').onStatus('" + this.id + "', " + MEDIA_POSITION + ", " + milliseconds / 1000.0f + ");");
        }
        else {
            this.seekOnPrepared = milliseconds;
@@ -246,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('org.apache.cordova.core.AudioHandler.Media').onStatus('" + this.id + "', " + MEDIA_ERROR + ", { \"code\":" + MEDIA_ERR_NONE_ACTIVE + "});");
            this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.media.Media').onStatus('" + this.id + "', " + MEDIA_ERROR + ", { \"code\":" + MEDIA_ERR_NONE_ACTIVE + "});");
        }
    }

@@ -262,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('org.apache.cordova.core.AudioHandler.Media').onStatus('" + this.id + "', " + MEDIA_ERROR + ", { \"code\":" + MEDIA_ERR_NONE_ACTIVE + "});");
            this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.media.Media').onStatus('" + this.id + "', " + MEDIA_ERROR + ", { \"code\":" + MEDIA_ERR_NONE_ACTIVE + "});");
        }
    }

@@ -284,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('org.apache.cordova.core.AudioHandler.Media').onStatus('" + this.id + "', " + MEDIA_POSITION + ", " + curPos / 1000.0f + ");");
            this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.media.Media').onStatus('" + this.id + "', " + MEDIA_POSITION + ", " + curPos / 1000.0f + ");");
            return curPos;
        }
        else {
@@ -363,7 +363,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
        this.prepareOnly = true;

        // Send status notification to JavaScript
        this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.core.AudioHandler.Media').onStatus('" + this.id + "', " + MEDIA_DURATION + "," + this.duration + ");");
        this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.media.Media').onStatus('" + this.id + "', " + MEDIA_DURATION + "," + this.duration + ");");
    }

    /**
@@ -391,7 +391,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
        this.player.release();

        // Send error notification to JavaScript
        this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.core.AudioHandler.Media').onStatus('" + this.id + "', { \"code\":" + arg1 + "});");
        this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.media.Media').onStatus('" + this.id + "', { \"code\":" + arg1 + "});");
        return false;
    }

@@ -402,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('org.apache.cordova.core.AudioHandler.Media').onStatus('" + this.id + "', " + MEDIA_STATE + ", " + state.ordinal() + ");");
            this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.media.Media').onStatus('" + this.id + "', " + MEDIA_STATE + ", " + state.ordinal() + ");");
        }
        this.state = state;
    }
@@ -415,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('org.apache.cordova.core.AudioHandler.Media').onStatus('" + this.id + "', " + MEDIA_STATE + ", " + mode + ");");
            //this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.media.Media').onStatus('" + this.id + "', " + MEDIA_STATE + ", " + mode + ");");
        }
        this.mode = mode;
    }
@@ -451,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('org.apache.cordova.core.AudioHandler.Media').onStatus('" + this.id + "', " + MEDIA_ERROR + ", { \"code\":" + MEDIA_ERR_ABORTED + "});");
            this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.media.Media').onStatus('" + this.id + "', " + MEDIA_ERROR + ", { \"code\":" + MEDIA_ERR_ABORTED + "});");
            return false; //player is not ready
        }
        return true;
@@ -472,7 +472,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
                    try {
                        this.loadAudioFile(file);
                    } catch (Exception e) {
                        this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.core.AudioHandler.Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", { \"code\":"+MEDIA_ERR_ABORTED+"});");
                        this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.media.Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", { \"code\":"+MEDIA_ERR_ABORTED+"});");
                    }
                    return false;
                case MEDIA_LOADING:
@@ -497,14 +497,14 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
                        try {
                            this.loadAudioFile(file);
                        } catch (Exception e) {
                            this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.core.AudioHandler.Media').onStatus('" + this.id + "', " + MEDIA_ERROR + ", { \"code\":" + MEDIA_ERR_ABORTED + "});");
                            this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.media.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('org.apache.cordova.core.AudioHandler.Media').onStatus('" + this.id + "', " + MEDIA_ERROR + ", { \"code\":" + MEDIA_ERR_ABORTED + "});");
                    this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.media.Media').onStatus('" + this.id + "', " + MEDIA_ERROR + ", { \"code\":" + MEDIA_ERR_ABORTED + "});");
            }
        }
        return false;
@@ -541,7 +541,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
                    fileInputStream.close();
                }
                else {
                    this.player.setDataSource("/sdcard/" + file);
                    this.player.setDataSource(Environment.getExternalStorageDirectory().getPath() + "/" + file);
                }
            }
                this.setState(STATE.MEDIA_STARTING);
+38 −0
Changes for src/android/FileHelper.java: 38 added lines, 0 removed lines.
Original line number Diff line number Diff line
/*
       Licensed to the Apache Software Foundation (ASF) under one
       or more contributor license agreements.  See the NOTICE file
       distributed with this work for additional information
       regarding copyright ownership.  The ASF licenses this file
       to you under the Apache License, Version 2.0 (the
       "License"); you may not use this file except in compliance
       with the License.  You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

       Unless required by applicable law or agreed to in writing,
       software distributed under the License is distributed on an
       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
       KIND, either express or implied.  See the License for the
       specific language governing permissions and limitations
       under the License.
 */
package org.apache.cordova.media;

import android.net.Uri;

public class FileHelper {

    /**
     * Removes the "file://" prefix from the given URI string, if applicable.
     * If the given URI string doesn't have a "file://" prefix, it is returned unchanged.
     *
     * @param uriString the URI string to operate on
     * @return a path without the "file://" prefix
     */
    public static String stripFileProtocol(String uriString) {
        if (uriString.startsWith("file://")) {
            return Uri.parse(uriString).getPath();
        }
        return uriString;
    }
}
Loading