incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From purplecabb...@apache.org
Subject [2/3] js commit: [COMMON] cleanup Media.onStatus, handles null media case, logs errors if logging is available
Date Fri, 07 Sep 2012 21:14:13 GMT
[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 <purplecabbage@gmail.com>
Authored: Thu Sep 6 13:02:14 2012 -0700
Committer: Jesse MacFadyen <purplecabbage@gmail.com>
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


Mime
View raw message