Example usage for org.apache.cordova.file FileHelper stripFileProtocol

List of usage examples for org.apache.cordova.file FileHelper stripFileProtocol

Introduction

In this page you can find the example usage for org.apache.cordova.file FileHelper stripFileProtocol.

Prototype

public static String stripFileProtocol(String uriString) 

Source Link

Document

Removes the "file://" prefix from the given URI string, if applicable.

Usage

From source file:com.pearson.plugins.audio.PearsonAudioHandler.java

License:Apache License

/**
 * Executes the request and returns PluginResult.
 * /*from w  w w .  j  a v  a  2 s  .  c  o m*/
 * @param action
 *            The action to execute.
 * @param args
 *            JSONArry of arguments for the plugin.
 * @param callbackContext
 *            The callback context used when calling back into JavaScript.
 * @return A PluginResult object with a status and message.
 */
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    CordovaResourceApi resourceApi = webView.getResourceApi();
    PluginResult.Status status = PluginResult.Status.OK;
    String result = "";
    System.out.println("EXECUTED::" + action);
    if (action.equals("startPlayingAudio")) {
        String target = args.getString(1);
        String fileUriStr;
        try {
            Uri targetUri = resourceApi.remapUri(Uri.parse(target));
            fileUriStr = targetUri.toString();
        } catch (IllegalArgumentException e) {
            fileUriStr = target;
        }
        this.startPlayingAudio(args.getString(0), FileHelper.stripFileProtocol(fileUriStr));
    } else if (action.equals("seekToAudio")) {
        this.seekToAudio(args.getString(0), args.getInt(1));
    } else if (action.equals("pausePlayingAudio")) {
        this.pausePlayingAudio(args.getString(0));
    } else if (action.equals("stopPlayingAudio")) {
        this.stopPlayingAudio(args.getString(0));
    } else if (action.equals("setVolume")) {
        try {
            this.setVolume(args.getString(0), Float.parseFloat(args.getString(1)));
        } catch (NumberFormatException nfe) {
            // no-op
        }
    } else if (action.equals("getCurrentPositionAudio")) {
        float f = this.getCurrentPositionAudio(args.getString(0));
        callbackContext.sendPluginResult(new PluginResult(status, f));
        return true;
    } else if (action.equals("getDurationAudio")) {
        float f = this.getDurationAudio();
        callbackContext.sendPluginResult(new PluginResult(status, f));
        return true;
    } else if (action.equals("create")) {
        String id = args.getString(0);
        String src = FileHelper.stripFileProtocol(args.getString(1));
        PearsonAudioPlayer audio = new PearsonAudioPlayer(this, id, src);
        // this.player.put(id, audio);
        System.out.println("CREATED");
        this.player = audio;
    } else if (action.equals("release")) {
        boolean b = this.release(args.getString(0));
        callbackContext.sendPluginResult(new PluginResult(status, b));
        return true;
    } else if (action.equals("setPlayBackRate")) {
        this.setPlayBackRate(args.getInt(1));
    } else { // Unrecognized action.
        return false;
    }

    callbackContext.sendPluginResult(new PluginResult(status, result));

    return true;
}