[Media] Adding support for virtual paths
authorLukasz Foniok <l.foniok@samsung.com>
Fri, 11 Dec 2015 20:05:47 +0000 (21:05 +0100)
committerLukasz Foniok <l.foniok@samsung.com>
Fri, 11 Dec 2015 20:05:47 +0000 (21:05 +0100)
Change-Id: Ieea45f5ff981e89a4ec42a6bb9e4b214aa5f7798
Signed-off-by: Lukasz Foniok <l.foniok@samsung.com>
sample/plugins/media/media.js
src/media/cordova_media.gyp
src/media/cordova_media_api.js
src/media/cordova_media_extension.cc
src/media/cordova_media_extension.h
src/media/cordova_media_instance.cc [new file with mode: 0644]
src/media/cordova_media_instance.h [new file with mode: 0644]

index 405e2eb..28d344c 100644 (file)
@@ -35,7 +35,7 @@ var deviceReady = function () {
       console.log(files[i].fullPath);
       if(!(files[i].name in playfiles) ){
         playfiles[files[i].name] =  files[i];
-        table.row.add([i + '.', '/opt/usr/media/Documents/' + files[i].name]).draw(false);
+        table.row.add([i + '.', 'documents/' + files[i].name]).draw(false);
       }
     }
   });
@@ -200,7 +200,7 @@ function stopRecAudio() {
       console.log(files[i].fullPath);
       if(!(files[i].name in playfiles) ){
         playfiles[files[i].name] =  files[i];
-        table.row.add([i + '.', '/opt/usr/media/Documents/' + files[i].name]).draw(false);
+        table.row.add([i + '.', 'documents' + files[i].name]).draw(false);
       }
     }
   });
index 4a43c14..e94b863 100644 (file)
@@ -10,6 +10,8 @@
         'cordova_media_api.js',
         'cordova_media_extension.cc',
         'cordova_media_extension.h',
+        'cordova_media_instance.h',
+        'cordova_media_instance.cc',
       ],
       'include_dirs': [
         '../',
@@ -17,6 +19,7 @@
       ],
       'variables': {
         'packages': [
+          'storage',
           'webapi-plugins',
         ],
       },
index f9f3931..4398e60 100755 (executable)
 // TODO: remove when added to public cordova repository -> begin
 var plugin_name = 'cordova-plugin-media.tizen.Media';
 
+var utils_ = xwalk.utils;
+var native_ = new utils_.NativeManager(extension);
+var privilege_ = xwalk.utils.privilege;
+
+function GetRealPath(virtualPath) {
+
+    console.log("JS GetRealPath " + virtualPath);
+    xwalk.utils.checkPrivilegeAccess(privilege_.FILESYSTEM_READ);
+
+    var data = {
+        path : virtualPath
+    };
+
+    var result = native_.callSync('CordovaMediaInstance_GetRealPath', data);
+    var fullResult = native_.getResultObject(result);
+    console.log("Result of call " +  fullResult.path);
+    return fullResult.path;
+}
+
 cordova.define(plugin_name, function(require, exports, module) {
 // TODO: remove -> end
 
@@ -212,9 +231,10 @@ cordova.define(plugin_name, function(require, exports, module) {
   create: function(successCallback, errorCallback, args) {
     var id = args[0], src = args[1];
 
-    console.log('media::create() - id =' + id + ', src =' + src);
+    var realPath = GetRealPath(src);
+    console.log('media::create() - id =' + id + ', src =' + realPath);
 
-    recorder = new Recorder(src);
+    recorder = new Recorder(realPath);
     audioObjects[id] = new Audio();
     audioObjects[id].isReady = false;
 
@@ -304,7 +324,8 @@ cordova.define(plugin_name, function(require, exports, module) {
   startPlayingAudio: function(successCallback, errorCallback, args) {
     var id = args[0], src = args[1];
 
-    console.log('media::startPlayingAudio() - id =' + id + ', src =' + src);
+    var realPath = GetRealPath(src);
+    console.log('media::startPlayingAudio() - id =' + id + ', src =' + realPath);
 
     audioObjects[id].isReady = true;
 
@@ -314,7 +335,7 @@ cordova.define(plugin_name, function(require, exports, module) {
       //it should be saved and restored.
       var rate = audioObjects[id].playbackRate;
 
-      audioObjects[id].src = src;
+      audioObjects[id].src = realPath;
       audioObjects[id].playbackRate = rate;
       return;
     }
@@ -366,7 +387,7 @@ cordova.define(plugin_name, function(require, exports, module) {
       var id = args[0];
       console.log('media::getCurrentPositionAudio()');
       if (audioObjects[id].src === 'undefined') {
-          audioObjects[id].src = args[1];
+          audioObjects[id].src = GetRealPath(args[1]);
       }
       successCallback(audioObjects[id].currentTime);
   },
@@ -374,7 +395,7 @@ cordova.define(plugin_name, function(require, exports, module) {
       var id = args[0];
       console.log('media::startRecordingAudio()');
       if (audioObjects[id].src === 'undefined') {
-          audioObjects[id].src = args[1];
+          audioObjects[id].src = GetRealPath(args[1]);
       }
       recorder.rec();
   },
@@ -382,7 +403,7 @@ cordova.define(plugin_name, function(require, exports, module) {
       var id = args[0];
       console.log('media::stopRecordingAudio()');
       if (audioObjects[id].src === 'undefined') {
-          audioObjects[id].src = args[1];
+          audioObjects[id].src = GetRealPath(args[1]);
       }
       recorder.stop();
   },
index 6565afc..98462f1 100755 (executable)
@@ -15,6 +15,7 @@
  */
 
 #include "media/cordova_media_extension.h"
+#include "media/cordova_media_instance.h"
 
 // This will be generated from cordova_media_api.js
 extern const char kSource_cordova_media_api[];
@@ -34,6 +35,11 @@ CordovaMediaExtension::CordovaMediaExtension() {
 
 CordovaMediaExtension::~CordovaMediaExtension() {}
 
+common::Instance* CordovaMediaExtension::CreateInstance() {
+  LoggerD("Entered");
+  return new extension::cordova::media::CordovaMediaInstance();
+}
+
 }  // media
 }  // cordova
 }  // extension
index 3db047c..9575086 100755 (executable)
@@ -27,6 +27,10 @@ class CordovaMediaExtension : public common::Extension {
  public:
   CordovaMediaExtension();
   virtual ~CordovaMediaExtension();
+
+ private:
+  // common::Extension implementation.
+  virtual common::Instance* CreateInstance();
 };
 
 }  //media
diff --git a/src/media/cordova_media_instance.cc b/src/media/cordova_media_instance.cc
new file mode 100644 (file)
index 0000000..6fe8c71
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed 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.
+ */
+
+#include "media/cordova_media_instance.h"
+#include <common/logger.h>
+
+namespace extension {
+namespace cordova {
+namespace media {
+
+CordovaMediaInstance::CordovaMediaInstance(): fs_provider_(common::FilesystemProviderStorage::Create()) {
+    LoggerD("Entered");
+
+    RegisterSyncHandler("CordovaMediaInstance_GetRealPath",
+        std::bind(&CordovaMediaInstance::GetRealPath, this, std::placeholders::_1, std::placeholders::_2));
+
+}
+
+CordovaMediaInstance::~CordovaMediaInstance() {
+}
+
+void CordovaMediaInstance::GetRealPath(const picojson::value& args, picojson::object& out) {
+  LoggerD("Entered");
+
+  const std::string& path_str =  args.get("path").get<std::string>();
+
+  picojson::value retval = picojson::value(picojson::object());
+  picojson::object& obj = retval.get<picojson::object>();
+
+  LoggerD("Path is %s", path_str.c_str());
+  std::string realPath = fs_provider_.GetRealPath(path_str);
+  obj["path"] = picojson::value(realPath);
+  LoggerD("Real Path is %s", realPath.c_str());
+  ReportSuccess(retval,out);
+}
+
+}
+}
+} /* namespace media */
diff --git a/src/media/cordova_media_instance.h b/src/media/cordova_media_instance.h
new file mode 100644 (file)
index 0000000..ba6e23f
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed 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.
+ */
+
+#ifndef MEDIA_CORDOVA_MEDIA_EXTENSION_H_
+#define MEDIA_CORDOVA_MEDIA_EXTENSION_H_
+
+#include <common/extension.h>
+#include <common/picojson.h>
+#include <common/filesystem/filesystem_provider_storage.h>
+
+namespace extension {
+namespace cordova {
+namespace media {
+
+class CordovaMediaInstance : public common::ParsedInstance {
+ public:
+  CordovaMediaInstance();
+  virtual ~CordovaMediaInstance();
+
+ private:
+  common::FilesystemProviderStorage& fs_provider_;
+  void GetRealPath(const picojson::value& args, picojson::object& out);
+};
+
+}
+}
+} /* namespace media */
+
+#endif // MEDIA_CORDOVA_MEDIA_EXTENSION_H_