Return-Path: X-Original-To: apmail-cordova-commits-archive@www.apache.org Delivered-To: apmail-cordova-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D8CF910CB4 for ; Mon, 17 Jun 2013 13:51:02 +0000 (UTC) Received: (qmail 13190 invoked by uid 500); 17 Jun 2013 13:51:02 -0000 Delivered-To: apmail-cordova-commits-archive@cordova.apache.org Received: (qmail 12661 invoked by uid 500); 17 Jun 2013 13:50:58 -0000 Mailing-List: contact commits-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cordova.apache.org Delivered-To: mailing list commits@cordova.apache.org Received: (qmail 12653 invoked by uid 99); 17 Jun 2013 13:50:57 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 17 Jun 2013 13:50:57 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 5513F8A5DDA; Mon, 17 Jun 2013 13:50:57 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: bhiggins@apache.org To: commits@cordova.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: webworks commit: [CB-3438] Add media plugin to BB10 Date: Mon, 17 Jun 2013 13:50:57 +0000 (UTC) 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 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 Authored: Mon Jun 10 17:00:47 2013 -0400 Committer: Bryan Higgins 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 @@ + + + + + + Media + + + + + + + + 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(); + } +};