Added Dailymotion support popcorn-port
authorveltr
Tue, 07 Feb 2012 14:41:05 +0100
branchpopcorn-port
changeset 785 980163a156d1
parent 784 2ce658b19b96
child 786 91c54c9f5824
Added Dailymotion support
src/js/init.js
src/js/players/player.dailymotion.js
src/js/pop.js
test/integration/polemic-youtube.htm
--- a/src/js/init.js	Mon Feb 06 16:05:08 2012 +0100
+++ b/src/js/init.js	Tue Feb 07 14:41:05 2012 +0100
@@ -117,7 +117,11 @@
           
           pop = Popcorn.youtube("#" + containerDiv, opts.video, opts);
         break;
-        
+      
+    case "dailymotion":
+        pop = new IriSP.PopcornReplacement.dailymotion("#" + containerDiv, options);
+        break;
+             
       case "allocine":
           /* pass the options as-is to the allocine player and let it handle everything */
           pop = new IriSP.PopcornReplacement.allocine("#" + containerDiv, options);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/js/players/player.dailymotion.js	Tue Feb 07 14:41:05 2012 +0100
@@ -0,0 +1,86 @@
+/* To wrap a player the develop should create a new class derived from
+the IriSP.PopcornReplacement.player and defining the correct functions */
+
+/** jwplayer player wrapper */
+IriSP.PopcornReplacement.dailymotion = function(container, options) {
+    /* appel du parent pour initialiser les structures communes à tous les players */
+    IriSP.PopcornReplacement.player.call(this, container, options);
+
+    var _this = this;
+
+    /* Définition des fonctions de l'API -  */
+
+    this.playerFns = {
+        play : function() {
+            return _this.player.playVideo();
+        },
+        pause : function() {
+            return _this.player.pauseVideo();
+        },
+        getPosition : function() {
+            return _this.player.getCurrentTime();
+        },
+        seek : function(pos) {
+            return _this.player.seekTo(pos);
+        },
+        getMute : function() {
+            return _this.player.isMuted();
+        },
+        setMute : function(p) {
+            return p ? _this.player.mute() : _this.player.unMute();
+        }
+    }
+
+    window.onDailymotionPlayerReady = IriSP.wrap(this, this.ready);
+    window.onDailymotionStateChange = IriSP.wrap(this, this.stateHandler);
+    window.onDailymotionVideoProgress = IriSP.wrap(this, this.progressHandler);
+
+    var params = {
+        allowScriptAccess : "always"
+    };
+    var atts = {
+        id : this.container
+    };
+    swfobject.embedSWF("http://www.dailymotion.com/swf?chromeless=1&enableApi=1", this.container, options.width, options.height, "8", null, null, params, atts);
+
+};
+
+IriSP.PopcornReplacement.dailymotion.prototype = new IriSP.PopcornReplacement.player("", {});
+
+IriSP.PopcornReplacement.dailymotion.prototype.ready = function() {
+    
+    this.player = document.getElementById(this.container);
+    
+    this.player.addEventListener("onStateChange", "onDailymotionStateChange");
+    this.player.addEventListener("onVideoProgress", "onDailymotionVideoProgress");
+    this.player.loadVideoByUrl(this._options.video);
+};
+
+IriSP.PopcornReplacement.dailymotion.prototype.progressHandler = function(progressInfo) {
+    
+    this.callbacks.onTime({
+        position: progressInfo.mediaTime
+    });
+}
+
+IriSP.PopcornReplacement.dailymotion.prototype.stateHandler = function(state) {
+    
+    switch(state) {
+        case 1:
+            this.callbacks.onPlay();
+            break;
+
+        case 2:
+            this.callbacks.onPause();
+            break;
+
+        case 3:
+            this.callbacks.onSeek();
+            break;
+
+        case 5:
+            this.callbacks.onReady();
+            break;
+    }
+    
+};
--- a/src/js/pop.js	Mon Feb 06 16:05:08 2012 +0100
+++ b/src/js/pop.js	Tue Feb 07 14:41:05 2012 +0100
@@ -27,6 +27,8 @@
   this.msgPump = {}; /* dictionnary used to receive and send messages */
   this.__codes = []; /* used to schedule the execution of a piece of code in 
                         a segment (similar to the popcorn.code plugin). */
+  
+  this._options = options;
                           
 };
 
--- a/test/integration/polemic-youtube.htm	Mon Feb 06 16:05:08 2012 +0100
+++ b/test/integration/polemic-youtube.htm	Tue Feb 07 14:41:05 2012 +0100
@@ -96,9 +96,9 @@
 					  ]
 			  },
 			player:{
-			type:'youtube', // player type
+			type:'dailymotion', // player type
 			  // the rest is player-dependent configuration options.
-			  video: "http://www.youtube.com/watch?v=rrkrvAUbU9Y", 
+			  video: "http://www.dailymotion.com/video/xodjrx", 
 			  height: 300, 
 			  width: 640, 
             }