Return-Path: X-Original-To: apmail-incubator-callback-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-callback-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8D653D51A for ; Fri, 7 Sep 2012 21:14:14 +0000 (UTC) Received: (qmail 19176 invoked by uid 500); 7 Sep 2012 21:14:14 -0000 Delivered-To: apmail-incubator-callback-commits-archive@incubator.apache.org Received: (qmail 19164 invoked by uid 500); 7 Sep 2012 21:14:14 -0000 Mailing-List: contact callback-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: callback-dev@incubator.apache.org Delivered-To: mailing list callback-commits@incubator.apache.org Received: (qmail 19091 invoked by uid 99); 7 Sep 2012 21:14:14 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 07 Sep 2012 21:14:14 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 1740928324; Fri, 7 Sep 2012 21:14:13 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: purplecabbage@apache.org To: callback-commits@incubator.apache.org X-Mailer: ASF-Git Admin Mailer Subject: [2/3] js commit: [COMMON] cleanup Media.onStatus, handles null media case, logs errors if logging is available Message-Id: <20120907211414.1740928324@tyr.zones.apache.org> Date: Fri, 7 Sep 2012 21:14:13 +0000 (UTC) [COMMON] cleanup Media.onStatus, handles null media case, logs errors if logging is available Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/commit/4214ffe2 Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/4214ffe2 Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/4214ffe2 Branch: refs/heads/master Commit: 4214ffe2c319608cd1065caed5e6e4ddd4720fd9 Parents: 490465b Author: Jesse MacFadyen Authored: Thu Sep 6 13:02:14 2012 -0700 Committer: Jesse MacFadyen Committed: Thu Sep 6 13:02:14 2012 -0700 ---------------------------------------------------------------------- lib/common/plugin/Media.js | 51 +++++++++++++++++++++----------------- 1 files changed, 28 insertions(+), 23 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/4214ffe2/lib/common/plugin/Media.js ---------------------------------------------------------------------- diff --git a/lib/common/plugin/Media.js b/lib/common/plugin/Media.js index 6b5310d..281ca94 100644 --- a/lib/common/plugin/Media.js +++ b/lib/common/plugin/Media.js @@ -153,34 +153,39 @@ Media.prototype.setVolume = function(volume) { * PRIVATE * * @param id The media object id (string) - * @param status The status code (int) - * @param msg The status message (string) + * @param msgType The 'type' of update this is + * @param value Use of value is determined by the msgType */ -Media.onStatus = function(id, msg, value) { +Media.onStatus = function(id, msgType, value) { + var media = mediaObjects[id]; - // If state update - if (msg === Media.MEDIA_STATE) { - if (media.statusCallback) { - media.statusCallback(value); - } - if (value === Media.MEDIA_STOPPED) { - if (media.successCallback) { - media.successCallback(); - } - } - } - else if (msg === Media.MEDIA_DURATION) { - media._duration = value; - } - else if (msg === Media.MEDIA_ERROR) { - if (media.errorCallback) { - // value should be a MediaError object when msg == MEDIA_ERROR - media.errorCallback(value); + + if(media) { + switch(msgType) { + case Media.MEDIA_STATE : + media.statusCallback && media.statusCallback(value); + if(value == Media.MEDIA_STOPPED) { + media.successCallback && media.successCallback(); + } + break; + case Media.MEDIA_DURATION : + media._duration = value; + break; + case Media.MEDIA_ERROR : + media.errorCallback && media.errorCallback({'code':value}); + break; + case Media.MEDIA_POSITION : + media._position = Number(value); + break; + default : + console.error("Unhandled Media.onStatus :: " + msgType); + break; } } - else if (msg === Media.MEDIA_POSITION) { - media._position = value; + else { + console.error("Received Media.onStatus callback for unknown media :: " + id); } + }; module.exports = Media; \ No newline at end of file