cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bhigg...@apache.org
Subject webworks commit: [CB-3438] Add media plugin to BB10
Date Mon, 17 Jun 2013 13:50:57 GMT
Updated Branches:
  refs/heads/master 6fd732391 -> 06acc708b


[CB-3438] Add media plugin to BB10

- media operations handled in controller web view
- added code to prevent error dialog from freezing app

Tested by Tracy Li <tli@blackberry.com>


Project: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/commit/06acc708
Tree: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/tree/06acc708
Diff: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/diff/06acc708

Branch: refs/heads/master
Commit: 06acc708bd4cbc560589d5a9f298ee4fdc225a2c
Parents: 6fd7323
Author: Bryan Higgins <bhiggins@blackberry.com>
Authored: Mon Jun 10 17:00:47 2013 -0400
Committer: Bryan Higgins <bhiggins@blackberry.com>
Committed: Mon Jun 17 09:54:28 2013 -0400

----------------------------------------------------------------------
 blackberry10/javascript/cordova.blackberry10.js |   3 +-
 blackberry10/plugins/Media/plugin.xml           |  30 +++
 .../plugins/Media/src/blackberry10/index.js     | 232 +++++++++++++++++++
 3 files changed, 263 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/06acc708/blackberry10/javascript/cordova.blackberry10.js
----------------------------------------------------------------------
diff --git a/blackberry10/javascript/cordova.blackberry10.js b/blackberry10/javascript/cordova.blackberry10.js
index e97f404..d3020aa 100644
--- a/blackberry10/javascript/cordova.blackberry10.js
+++ b/blackberry10/javascript/cordova.blackberry10.js
@@ -795,7 +795,6 @@ var cordova = require('cordova'),
     plugins = {
         'Compass' : require('cordova/plugin/blackberry10/magnetometer'),
         'Capture' : require('cordova/plugin/blackberry10/capture'),
-        'Media': require('cordova/plugin/blackberry10/media'),
         'FileTransfer': require('cordova/plugin/blackberry10/fileTransfer')
     };
 
@@ -6891,4 +6890,4 @@ document.addEventListener("DOMContentLoaded", function () {
 }(window));
 
 
-})();
\ No newline at end of file
+})();

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/06acc708/blackberry10/plugins/Media/plugin.xml
----------------------------------------------------------------------
diff --git a/blackberry10/plugins/Media/plugin.xml b/blackberry10/plugins/Media/plugin.xml
new file mode 100644
index 0000000..1162c9c
--- /dev/null
+++ b/blackberry10/plugins/Media/plugin.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+
+-->
+
+<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
+    id="org.apache.cordova.core.Media"
+    version="0.0.1">
+
+    <name>Media</name>
+
+    <platform name="blackberry10">
+        <source-file src="src/blackberry10/index.js" target-dir="Media" />
+        <config-file target="www/config.xml" parent="/widget">
+            <feature name="Media" value="Media"/>
+        </config-file>
+    </platform>
+</plugin>

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/06acc708/blackberry10/plugins/Media/src/blackberry10/index.js
----------------------------------------------------------------------
diff --git a/blackberry10/plugins/Media/src/blackberry10/index.js b/blackberry10/plugins/Media/src/blackberry10/index.js
new file mode 100644
index 0000000..32192c8
--- /dev/null
+++ b/blackberry10/plugins/Media/src/blackberry10/index.js
@@ -0,0 +1,232 @@
+/*
+ * Copyright 2010-2011 Research In Motion Limited.
+ *
+ * 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.
+ */
+
+var audioObjects = {},
+    mediaErrorsHandled = false;
+
+// There is a bug in the webplatform handling of media error
+// dialogs prior to 10.2. This function needs to be run once
+// on the webview which plays audio to prevent freezing.
+function handleMediaErrors() {
+    var webview = qnx.webplatform.getWebViews()[0],
+        handler = webview.onDialogRequested;
+    if (!mediaErrorsHandled) {
+        webview.allowWebEvent("DialogRequested");
+        webview.onDialogRequested = undefined;
+        webview.onDialogRequested = function (eventArgs) {
+            var parsedArgs = JSON.parse(eventArgs);
+            if (parsedArgs.dialogType === 'MediaError') {
+                return '{"setPreventDefault": true}';
+            }
+            handler(eventArgs);
+        };
+        mediaErrorsHandled = true;
+    }
+}
+
+module.exports = {
+
+    create: function (success, fail, args, env) {
+        var result = new PluginResult(args, env),
+            id;
+
+        if (!args[0]) {
+            result.error("Media Object id was not sent in arguments");
+            return;
+        }
+
+        id = JSON.parse(decodeURIComponent(args[0]));
+
+        if (!args[1]){
+            audioObjects[id] = new Audio();
+        } else {
+            audioObjects[id] = new Audio(JSON.parse(decodeURIComponent(args[1])));
+        }
+
+        handleMediaErrors();
+
+        result.ok();
+    },
+
+    startPlayingAudio: function (success, fail, args, env) {
+
+        var audio,
+            id,
+            result = new PluginResult(args, env);
+
+        if (!args[0]) {
+            result.error("Media Object id was not sent in arguments");
+            return;
+        }
+
+        id = JSON.parse(decodeURIComponent(args[0]));
+
+        audio = audioObjects[id];
+
+        if (!audio) {
+            result.error("Audio object has not been initialized");
+        } else {
+            audio.play();
+            result.ok();
+        }
+    },
+
+    stopPlayingAudio: function (success, fail, args, env) {
+
+        var audio,
+            id,
+            result = new PluginResult(args, env);
+
+        if (!args[0]) {
+            result.error("Media Object id was not sent in arguments");
+            return;
+        }
+
+        id = JSON.parse(decodeURIComponent(args[0]));
+
+        audio = audioObjects[id];
+
+        if (!audio) {
+            result.error("Audio Object has not been initialized");
+            return;
+        }
+
+        audio.pause();
+        audio.currentTime = 0;
+
+        result.ok();
+    },
+
+    seekToAudio: function (success, fail, args, env) {
+
+        var audio,
+            result = new PluginResult(args, env);
+
+        if (!args[0]) {
+            result.error("Media Object id was not sent in arguments");
+            return;
+        }
+
+        audio = audioObjects[JSON.parse(decodeURIComponent(args[0]))];
+
+        if (!audio) {
+            result.error("Audio Object has not been initialized");
+        } else if (!args[1]) {
+            result.error("Media seek time argument not found");
+        } else {
+            try {
+                audio.currentTime = JSON.parse(decodeURIComponent(args[1])) / 1000;
+                result.ok();
+            } catch (e) {
+                result.error("Error seeking audio: " + e);
+            }
+        }
+    },
+
+    pausePlayingAudio: function (success, fail, args, env) {
+
+        var audio,
+            result = new PluginResult(args, env);
+
+        if (!args[0]) {
+            result.error("Media Object id was not sent in arguments");
+            return;
+        }
+
+        audio = audioObjects[JSON.parse(decodeURIComponent(args[0]))];
+
+        if (!audio) {
+            result.error("Audio Object has not been initialized");
+            return;
+        }
+
+        audio.pause();
+    },
+
+    getCurrentPositionAudio: function (success, fail, args, env) {
+
+        var audio,
+            result = new PluginResult(args, env);
+
+        if (!args[0]) {
+            result.error("Media Object id was not sent in arguments");
+            return;
+        }
+
+        audio = audioObjects[JSON.parse(decodeURIComponent(args[0]))];
+
+        if (!audio) {
+            result.error("Audio Object has not been initialized");
+            return;
+        }
+
+        result.ok(audio.currentTime);
+    },
+
+    getDuration: function (success, fail, args, env) {
+
+        var audio,
+            result = new PluginResult(args, env);
+
+        if (!args[0]) {
+            result.error("Media Object id was not sent in arguments");
+            return;
+        }
+
+        audio = audioObjects[JSON.parse(decodeURIComponent(args[0]))];
+
+        if (!audio) {
+            result.error("Audio Object has not been initialized");
+            return;
+        }
+
+        result.ok(audio.duration);
+    },
+
+    startRecordingAudio: function (success, fail, args, env) {
+        var result = new PluginResult(args, env);
+        result.error("Not supported");
+    },
+
+    stopRecordingAudio: function (success, fail, args, env) {
+        var result = new PluginResult(args, env);
+        result.error("Not supported");
+    },
+
+    release: function (success, fail, args, env) {
+        var audio,
+            id,
+            result = new PluginResult(args, env);
+
+        if (!args[0]) {
+            result.error("Media Object id was not sent in arguments");
+            return;
+        }
+
+        id = JSON.parse(decodeURIComponent(args[0]));
+
+        audio = audioObjects[id];
+
+        if (audio) {
+            if(audio.src !== ""){
+                audio.src = undefined;
+            }
+            audioObjects[id] = undefined;
+        }
+
+        result.ok();
+    }
+};


Mime
View raw message