Author: michiel
Date: 2009-06-25 13:43:49 +0200 (Thu, 25 Jun 2009)
New Revision: 36405

Modified:
   openimages/trunk/src/main/webapp/style/js/player.js
Log:
using 'maybe' only if there is nothing better ('probably'). Removed the 
reverse, simply using break if nothing better can be found. This improves 
simplicity and performance

Modified: openimages/trunk/src/main/webapp/style/js/player.js
===================================================================
--- openimages/trunk/src/main/webapp/style/js/player.js 2009-06-25 10:32:29 UTC 
(rev 36404)
+++ openimages/trunk/src/main/webapp/style/js/player.js 2009-06-25 11:43:49 UTC 
(rev 36405)
@@ -1,10 +1,10 @@
 /*
-  Inits and controls the video player based on the html5 videotag. Depends on 
jquery. It enables 
-  the use of three players in a generic way: video-tag, java player cortado 
(for ogg) and flash. 
+  Inits and controls the video player based on the html5 videotag. Depends on 
jquery. It enables
+  the use of three players in a generic way: video-tag, java player cortado 
(for ogg) and flash.
   Sifts through the sources provided by the video-tag to find a suitable 
player.
   This script borrows heavily from the rather brilliant one used at Steal This 
Footage which enables
-  a multitude of players: http://footage.stealthisfilm.com/ 
-  
+  a multitude of players: http://footage.stealthisfilm.com/
+
   @author: André van Toly
   @version: 0.1
   @params:
@@ -28,15 +28,13 @@
     var urls = $.map(sources, function(i) {
         return $(i).attr('src');
     });
-    types.reverse();    // check prefered one last
-    urls.reverse();
-    
+
     if (urls.length == 0) {
         //console.log("No source elements found");
         urls[0] = $(videotag).attr('src');
         types[0] = "unknown";
     }
-    
+
     if (videotag != undefined) {
         var selectedPlayer = selectPlayer(types, urls);
         if (selectedPlayer.type == 'video') {
@@ -45,7 +43,7 @@
             player = new CortadoPlayer();
         } else if (selectedPlayer.type == 'flash') {
             player = new FlowPlayer();
-        } else { 
+        } else {
             player = new Player();
         }
         //console.log("type/url: " + selectedPlayer.type + " / " + 
selectedPlayer.url);
@@ -77,16 +75,16 @@
 Player.prototype.init = function(id, url, config) {
     return this._init(id, config);
 }
-Player.prototype.play = function() { 
+Player.prototype.play = function() {
     this.state = 'play';
 }
-Player.prototype.pause = function() { 
+Player.prototype.pause = function() {
     this.state = 'pause';
 }
 Player.prototype.position = function() { }
 Player.prototype.info = function() { return "Playing: " + this.url; }
 
-function VideoPlayer() { 
+function VideoPlayer() {
     this.myname = "videoplayer";
 }
 VideoPlayer.prototype = new Player();
@@ -116,8 +114,8 @@
     }
     return -1;
 }
-VideoPlayer.prototype.info = function() { 
-    //return "Playing: " + this.url; 
+VideoPlayer.prototype.info = function() {
+    //return "Playing: " + this.url;
 }
 
 function CortadoPlayer() {
@@ -174,11 +172,11 @@
 //         this.player.doStop();
 //     } catch(err) { }
 }
-CortadoPlayer.prototype.position = function() { 
+CortadoPlayer.prototype.position = function() {
     return this.player.getPlayPosition()
 }
-CortadoPlayer.prototype.info = function() {  
-    //return "Playing: " + this.url"; 
+CortadoPlayer.prototype.info = function() {
+    //return "Playing: " + this.url";
 }
 
 function FlowPlayer() {
@@ -198,7 +196,7 @@
         },
         plugins: { controls: null }
     });
-    
+
     return this.player;
 }
 
@@ -212,12 +210,12 @@
     this.state = 'pause';
 }
 
-FlowPlayer.prototype.position = function() { 
+FlowPlayer.prototype.position = function() {
     return this.player.getTime();
 }
 
-FlowPlayer.prototype.info = function() {  
-    //return "Playing: " + this.url; 
+FlowPlayer.prototype.info = function() {
+    //return "Playing: " + this.url;
 }
 
 /* Selects which player to use. Adapt this to change the prefered order, in 
this video, cortado, flash. */
@@ -228,7 +226,7 @@
         proposal.type = "video";
         proposal.url = probably;
     }
-    
+
     if (proposal.type == undefined) {
         probably = canPlayCortado(types, urls);
         if (probably != undefined && 
(supportMimetype('application/x-java-applet') || navigator.javaEnabled())) {
@@ -244,11 +242,11 @@
                     //console.log("4f: " + flash_url);
                 }
             }
-            
+
             proposal.url = flash_url;
-            
+
         }
-    } 
+    }
     //console.log("prop: " + proposal.type + ":" + proposal.url);
     return proposal;
 }
@@ -260,10 +258,11 @@
     var url;
     for (var i = 0; i < types.length; i++) {
         //console.log("testing: " + types[i]);
-        if (types[i].indexOf("video/ogg") > -1 || 
+        if (types[i].indexOf("video/ogg") > -1 ||
             types[i].indexOf("application/x-ogg") > -1 ||
             types[i].indexOf("audio/ogg") > -1) {
             url = urls[i];
+            break;
         }
     }
     //console.log("canPlayCortado: " + url);
@@ -277,29 +276,34 @@
     var probably;
     var el = document.createElement("video");
     if (el.canPlayType) {
-        for (var i = 0; i < types.length; i++) {
-            //console.log("testing v: " + types[i]);
+        for (var i = 0; i < types.length; i--) {
+            //console.log("testing v: " + types[i] + ": " + 
el.canPlayType(types[i])+ ":" + urls[i]);
             /*
              
http://www.whatwg.org/specs/web-apps/current-work/multipage/video.html#dom-navigator-canplaytype
              Firefox 3.5 is very strict about this and does not return 
'probably', but does on 'maybe'.
             */
-            if (el.canPlayType( types[i] ) == "maybe") {  // or 'maybe' for FF 
3.5 ?
+            //console.log(el.canPlayType( types[i] ));
+            if (el.canPlayType( types[i] ) == "probably") {
                 probably = urls[i];
+                break; // this is the best we can do
                 //console.log("found one: " + probably);
             }
+            if (el.canPlayType( types[i] ) == "maybe") {
+                probably = urls[i]; // if we find nothing better
+            }
         }
-        
+
         if (types.length == 0) {
             //console.log("No source elements found");
             var url = $(video).attr('src');
-            if (this_url != undefined && 
-                   (this_url.lastIndexOf('.mp4') > -1 || 
this_url.lastIndexOf('.h264') > -1 
+            if (this_url != undefined &&
+                   (this_url.lastIndexOf('.mp4') > -1 || 
this_url.lastIndexOf('.h264') > -1
                 )) {
                 //probably = "video/mp4";
                 probably = url;
             }
         }
-        
+
     }
     return probably;
 }

_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to