cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject [4/8] git commit: CB-6051: Update media plugin to work with new cdvfile:// urls
Date Fri, 28 Feb 2014 21:36:14 GMT
CB-6051: Update media plugin to work with new cdvfile:// urls


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/f96f2ac8
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/tree/f96f2ac8
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/diff/f96f2ac8

Branch: refs/heads/master
Commit: f96f2ac8cadfecf390a736fb94fe146b9bb0d4d8
Parents: 6380128
Author: Ian Clelland <iclelland@chromium.org>
Authored: Fri Feb 21 11:11:36 2014 -0500
Committer: Ian Clelland <iclelland@chromium.org>
Committed: Fri Feb 21 11:39:06 2014 -0500

----------------------------------------------------------------------
 src/android/AudioHandler.java |  9 +++++++--
 src/ios/CDVSound.m            | 18 +++++++++++++++++-
 2 files changed, 24 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/blob/f96f2ac8/src/android/AudioHandler.java
----------------------------------------------------------------------
diff --git a/src/android/AudioHandler.java b/src/android/AudioHandler.java
index 63d8580..40f7ea9 100644
--- a/src/android/AudioHandler.java
+++ b/src/android/AudioHandler.java
@@ -20,9 +20,11 @@ package org.apache.cordova.media;
 
 import org.apache.cordova.CallbackContext;
 import org.apache.cordova.CordovaPlugin;
+import org.apache.cordova.CordovaResourceApi;
 
 import android.content.Context;
 import android.media.AudioManager;
+import android.net.Uri;
 
 import java.util.ArrayList;
 
@@ -64,17 +66,20 @@ public class AudioHandler extends CordovaPlugin {
      * @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 = "";
 
         if (action.equals("startRecordingAudio")) {
-            this.startRecordingAudio(args.getString(0), FileHelper.stripFileProtocol(args.getString(1)));
+            Uri fileUri = resourceApi.remapUri(Uri.parse(args.getString(1)));
+            this.startRecordingAudio(args.getString(0), FileHelper.stripFileProtocol(fileUri.toString()));
         }
         else if (action.equals("stopRecordingAudio")) {
             this.stopRecordingAudio(args.getString(0));
         }
         else if (action.equals("startPlayingAudio")) {
-            this.startPlayingAudio(args.getString(0), FileHelper.stripFileProtocol(args.getString(1)));
+            Uri fileUri = resourceApi.remapUri(Uri.parse(args.getString(1)));
+            this.startPlayingAudio(args.getString(0), FileHelper.stripFileProtocol(fileUri.toString()));
         }
         else if (action.equals("seekToAudio")) {
             this.seekToAudio(args.getString(0), args.getInt(1));

http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/blob/f96f2ac8/src/ios/CDVSound.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVSound.m b/src/ios/CDVSound.m
index c8a3120..5364fcb 100644
--- a/src/ios/CDVSound.m
+++ b/src/ios/CDVSound.m
@@ -18,12 +18,14 @@
  */
 
 #import "CDVSound.h"
+#import "CDVFile.h"
 #import <Cordova/NSArray+Comparisons.h>
 #import <Cordova/CDVJSON.h>
 
 #define DOCUMENTS_SCHEME_PREFIX @"documents://"
 #define HTTP_SCHEME_PREFIX @"http://"
 #define HTTPS_SCHEME_PREFIX @"https://"
+#define CDVFILE_PREFIX @"cdvfile://"
 #define RECORDING_WAV @"wav"
 
 @implementation CDVSound
@@ -85,6 +87,13 @@
         // try to find Documents:// resources
         filePath = [resourcePath stringByReplacingOccurrencesOfString:DOCUMENTS_SCHEME_PREFIX
withString:[NSString stringWithFormat:@"%@/", docsPath]];
         NSLog(@"Will use resource '%@' from the documents folder with path = %@", resourcePath,
filePath);
+    } else if ([resourcePath hasPrefix:CDVFILE_PREFIX]) {
+        CDVFile *filePlugin = [self.commandDelegate getCommandInstance:@"File"];
+        CDVFilesystemURL *url = [CDVFilesystemURL fileSystemURLWithString:resourcePath];
+        filePath = [filePlugin filesystemPathForURL:url];
+        if (filePath == nil) {
+            resourceURL = [NSURL URLWithString:resourcePath];
+        }
     } else {
         // if resourcePath is not from FileSystem put in tmp dir, else attempt to use provided
resource path
         NSString* tmpPath = [NSTemporaryDirectory()stringByStandardizingPath];
@@ -122,6 +131,13 @@
         NSString* docsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,
YES)[0];
         filePath = [resourcePath stringByReplacingOccurrencesOfString:DOCUMENTS_SCHEME_PREFIX
withString:[NSString stringWithFormat:@"%@/", docsPath]];
         NSLog(@"Will use resource '%@' from the documents folder with path = %@", resourcePath,
filePath);
+    } else if ([resourcePath hasPrefix:CDVFILE_PREFIX]) {
+        CDVFile *filePlugin = [self.commandDelegate getCommandInstance:@"File"];
+        CDVFilesystemURL *url = [CDVFilesystemURL fileSystemURLWithString:resourcePath];
+        filePath = [filePlugin filesystemPathForURL:url];
+        if (filePath == nil) {
+            resourceURL = [NSURL URLWithString:resourcePath];
+        }
     } else {
         // attempt to find file path in www directory or LocalFileSystem.TEMPORARY directory
         filePath = [self.commandDelegate pathForResource:resourcePath];
@@ -141,7 +157,7 @@
             NSLog(@"Found resource '%@' in the web folder.", filePath);
         }
     }
-    // check that file exists for all but HTTP_SHEME_PREFIX
+    // if the resourcePath resolved to a file path, check that file exists
     if (filePath != nil) {
         // create resourceURL
         resourceURL = [NSURL fileURLWithPath:filePath];


Mime
View raw message