Commit before branch switch (for tests) players-as-widgets
authorveltr
Mon, 17 Sep 2012 22:44:59 +0900
branchplayers-as-widgets
changeset 958 2aa7fdb0762a
parent 957 4da0a5740b6c
child 959 ee11ed1b739e
Commit before branch switch (for tests)
doc/eventslist.txt
src/js/defaults.js
src/js/init.js
src/js/players/player.jwplayer.js
src/js/widgets.js
src/widgets/JwpPlayer.js
src/widgets/PopcornPlayer.js
test/jwplayer.htm
test/oggvideo.htm
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/doc/eventslist.txt	Mon Sep 17 22:44:59 2012 +0900
@@ -0,0 +1,8 @@
+Event Name                      Published by                    Subscribed by
+==============================  ==============================  ==============================  
+Annotation.hide                                                 Annotation
+Annotation.show                                                 Annotation
+Annotation.minimize                                             Annotation
+Annotation.maximize                                             Annotation
+Annotation.getBounds                                            Annotation
+Arrow.updatePosition            Annotation
\ No newline at end of file
--- a/src/js/defaults.js	Mon Sep 17 00:17:06 2012 +0900
+++ b/src/js/defaults.js	Mon Sep 17 22:44:59 2012 +0900
@@ -42,6 +42,14 @@
 IriSP.widgetsDir = 'widgets';
 
 IriSP.widgetsRequirements = {
+    PopcornPlayer: {
+        noCss: true,
+        requires: [ "popcorn" ]
+    },
+    JwpPlayer: {
+        noCss: true,
+        requires: [ "swfObject", "jwplayer" ]
+    },
     Sparkline: {
         noCss: true,
         requires: [ "raphael" ]
--- a/src/js/init.js	Mon Sep 17 00:17:06 2012 +0900
+++ b/src/js/init.js	Mon Sep 17 22:44:59 2012 +0900
@@ -1,4 +1,4 @@
-/* init.js - initialization and configuration of Popcorn and the widgets
+/* init.js - initialization and configuration of the widgets
 */
 
 if (typeof window.IriSP === "undefined") {
@@ -10,11 +10,11 @@
 IriSP.Metadataplayer = function(config) {
     IriSP.log("IriSP.Metadataplayer constructor");
     for (var key in IriSP.guiDefaults) {
-        if (IriSP.guiDefaults.hasOwnProperty(key) && !config.gui.hasOwnProperty(key)) {
-            config.gui[key] = IriSP.guiDefaults[key]
+        if (IriSP.guiDefaults.hasOwnProperty(key) && !config.hasOwnProperty(key)) {
+            config[key] = IriSP.guiDefaults[key]
         }
     }
-    var _container = document.getElementById(config.gui.container);
+    var _container = document.getElementById(config.container);
     _container.innerHTML = '<h3 class="Ldt-Loader">Loading... Chargement...</h3>';
     this.sourceManager = new IriSP.Model.Directory();
     this.config = config;
@@ -23,7 +23,7 @@
 }
 
 IriSP.Metadataplayer.prototype.toString = function() {
-    return 'Metadataplayer in #' + this.config.gui.container;
+    return 'Metadataplayer in #' + this.config.container;
 }
 
 IriSP.Metadataplayer.prototype.on = function(_event, _callback) {
@@ -45,8 +45,7 @@
     var $L = $LAB
         .script(IriSP.getLib("underscore"))
         .script(IriSP.getLib("Mustache"))
-        .script(IriSP.getLib("jQuery"))
-        .script(IriSP.getLib("swfObject"));
+        .script(IriSP.getLib("jQuery"));
     
     if (typeof JSON == "undefined") {
         $L.script(IriSP.getLib("json"));
@@ -55,17 +54,9 @@
     $L.wait()
         .script(IriSP.getLib("jQueryUI"));
 
-    if (this.config.player.type === "jwplayer" || this.config.player.type === "auto") {
-        $L.script(IriSP.getLib("jwplayer"));
-    }
-    
-    if (this.config.player.type !== "jwplayer" && this.config.player.type !== "allocine" && this.config.player.type !== "dailymotion") {
-        $L.script(IriSP.getLib("popcorn"));
-    }
-
     /* widget specific requirements */
-    for(var _i = 0; _i < this.config.gui.widgets.length; _i++) {
-        var _t = this.config.gui.widgets[_i].type;
+    for(var _i = 0; _i < this.config.widgets.length; _i++) {
+        var _t = this.config.widgets[_i].type;
         if (typeof IriSP.widgetsRequirements[_t] !== "undefined" && typeof IriSP.widgetsRequirements[_t].requires !== "undefined" ) {
             for (var _j = 0; _j < IriSP.widgetsRequirements[_t].requires.length; _j++) {
                 $L.script(IriSP.getLib(IriSP.widgetsRequirements[_t].requires[_j]));
@@ -89,22 +80,22 @@
         IriSP._ = window._;
     }
     IriSP.loadCss(IriSP.getLib("cssjQueryUI"));
-    IriSP.loadCss(this.config.gui.css);
+    IriSP.loadCss(this.config.css);
     
 //    this.videoData = this.loadMetadata(this.config.player.metadata);
-    this.$ = IriSP.jQuery('#' + this.config.gui.container);
+    this.$ = IriSP.jQuery('#' + this.config.container);
     this.$.css({
-        "width": this.config.gui.width,
+        "width": this.config.width,
         "clear": "both"
     });
-    if (typeof this.config.gui.height !== "undefined") {
-        this.$.css("height", this.config.gui.height);
+    if (typeof this.config.height !== "undefined") {
+        this.$.css("height", this.config.height);
     }
       
     this.widgets = [];
     var _this = this;
-    for(var i = 0; i < this.config.gui.widgets.length; i++) {
-        this.loadWidget(this.config.gui.widgets[i], function(_widget) {
+    for(var i = 0; i < this.config.widgets.length; i++) {
+        this.loadWidget(this.config.widgets[i], function(_widget) {
             _this.widgets.push(_widget)
         });
     };
@@ -313,8 +304,8 @@
     
     this.widgets = [];
     var _this = this;
-    for(var i = 0; i < this.config.gui.widgets.length; i++) {
-        this.loadWidget(this.config.gui.widgets[i], function(_widget) {
+    for(var i = 0; i < this.config.widgets.length; i++) {
+        this.loadWidget(this.config.widgets[i], function(_widget) {
             _this.widgets.push(_widget)
         });
     };
@@ -354,20 +345,20 @@
     if (typeof(_name) === "undefined") {
        _name = "";
     }
-    var newDiv = IriSP._.uniqueId(this.config.gui.container + "_widget_" + _name + "_"),
+    var newDiv = IriSP._.uniqueId(this.config.container + "_widget_" + _name + "_"),
         spacerDiv = IriSP._.uniqueId("LdtPlayer_spacer_"),
         divHtml = IriSP.jQuery('<div>')
             .attr("id",newDiv)
             .css({
-                width: this.config.gui.width + "px",
+                width: this.config.width + "px",
                 position: "relative",
                 clear: "both"
             }),
         spacerHtml = IriSP.jQuery('<div>')
             .attr("id",spacerDiv)
             .css({
-                width: this.config.gui.width + "px",
-                height: this.config.gui.spacer_div_height + "px",
+                width: this.config.width + "px",
+                height: this.config.spacer_div_height + "px",
                 position: "relative",
                 clear: "both"
             });
--- a/src/js/players/player.jwplayer.js	Mon Sep 17 00:17:06 2012 +0900
+++ b/src/js/players/player.jwplayer.js	Mon Sep 17 22:44:59 2012 +0900
@@ -13,7 +13,7 @@
         this.trigger("play");
     }
  
-    var _player = jwplayer(this.container),
+    var _player = jwplayer(this.$[0]),
         _this = this,
         _seekPause = false;
   
--- a/src/js/widgets.js	Mon Sep 17 00:17:06 2012 +0900
+++ b/src/js/widgets.js	Mon Sep 17 22:44:59 2012 +0900
@@ -26,7 +26,7 @@
     
     /* Setting all the configuration options */
     var _type = config.type,
-        _config = IriSP._.defaults({}, config, player.config.gui.default_options, this.defaults),
+        _config = IriSP._.defaults({}, config, player.config.default_options, this.defaults),
         _this = this;
     
     IriSP._(_config).forEach(function(_value, _key) {
@@ -34,7 +34,7 @@
     });
     
     if (typeof this.width === "undefined") {
-        this.width = player.config.gui.width;
+        this.width = player.config.width;
     }
     
     /* Setting this.player at the end in case it's been overriden
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/widgets/JwpPlayer.js	Mon Sep 17 22:44:59 2012 +0900
@@ -0,0 +1,120 @@
+IriSP.Widgets.JwpPlayer = function(player, config) {
+    IriSP.Widgets.Widget.call(this, player, config);
+};
+
+IriSP.Widgets.JwpPlayer.prototype = new IriSP.Widgets.Widget();
+
+IriSP.Widgets.JwpPlayer.prototype.defaults = {
+}
+
+IriSP.Widgets.JwpPlayer.prototype.draw = function() {
+
+    var _opts = {},
+        _player = jwplayer("#" + this.container),
+        _seekPause = false,
+        _pauseState = true,
+        _props = [ "live", "provider", "autostart" ];
+    
+    if (typeof this.video === "undefined") {
+        this.video = this.media.video;
+    }
+    
+    if (typeof this.streamer === "function") {
+        this.streamer = this.streamer(this.video);
+    }
+
+    if (typeof this.streamer === "string") {
+        this.video = this.video.replace(this.streamer,"");
+        _opts.streamer = this.streamer;
+    }
+        
+    _opts.file = this.video;
+    _opts.flashplayer = IriSP.getLib("jwPlayerSWF");
+    _opts["controlbar.position"] = "none";
+    
+    for (var i = 0; i < _props.length; i++) {
+        if (typeof this[_props[i]] !== "undefined") {
+            _opts[_props[i]] = this[_props[i]];
+        }
+    }
+    
+    if (this.autostart) {
+        _pauseState = false;
+        this.media.trigger("play");
+    }
+    // Binding functions to jwplayer
+
+    this.media.getCurrentTime = function() {
+        return new IriSP.Model.Time(1000*_player.getPosition());
+    }
+    this.media.getVolume = function() {
+        return _player.getVolume() / 100;
+    }
+    this.media.getPaused = function() {
+        return _pauseState;
+    }
+    this.media.getMuted = function() {
+        return _player.getMute();
+    }
+    this.media.setCurrentTime = function(_milliseconds) {
+        _seekPause = _pauseState;
+        return _player.seek(_milliseconds / 1000);
+    }
+    this.media.setVolume = function(_vol) {
+        return _player.setVolume(Math.floor(_vol*100));
+    }
+    this.media.mute = function() {
+        return _player.setMute(true);
+    }
+    this.media.unmute = function() {
+        return _player.setMute(false);
+    }
+    this.media.play = function() {
+        return _player.play(true);
+    }
+    this.media.pause = function() {
+        return _player.pause(true);
+    }
+    
+    // Binding jwplater events to media
+    
+    var _media = this.media;
+    
+    _opts.events = {
+        onReady: function() {
+            _media.trigger("loadedmetadata");
+        },
+        onTime: function() {
+            if (_seekPause) {
+                _player.pause(true);
+                _seekPause = false;
+            } else {
+                if (_pauseState && _player.getState() === "PLAYING") {
+                    _pauseState = false;
+                    _media.trigger("play");
+                }
+            }
+            _this.trigger("timeupdate", _media.getCurrentTime());
+        },
+        onPlay: function() {
+            if (!_seekPause) {
+                _pauseState = false;
+                _media.trigger("play");
+            }
+        },
+        onPause: function() {
+            _pauseState = true;
+            _media.trigger("pause");
+        },
+        onSeek: function() {
+            _media.trigger("seeked");
+        }
+    }
+    console.log("Before Setup", _opts);
+    _player.setup(_opts);
+    
+    console.log("OK");
+    
+    this.jwplayer = _player;
+    
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/widgets/PopcornPlayer.js	Mon Sep 17 22:44:59 2012 +0900
@@ -0,0 +1,88 @@
+IriSP.Widgets.PopcornPlayer = function(player, config) {
+    IriSP.Widgets.Widget.call(this, player, config);
+};
+
+IriSP.Widgets.PopcornPlayer.prototype = new IriSP.Widgets.Widget();
+
+IriSP.Widgets.PopcornPlayer.prototype.defaults = {
+}
+
+IriSP.Widgets.PopcornPlayer.prototype.draw = function() {
+    var _tmpId = Popcorn.guid("video"),
+        _videoEl = IriSP.jQuery('<video>');
+    
+    if (typeof this.video === "undefined") {
+        this.video = this.media.video;
+    }
+    
+    if (this.url_transform) {
+        this.video = this.url_transform(this.video);
+    }
+    
+    _videoEl.attr({
+        "src" : this.video,
+        "id" : _tmpId
+    })
+
+    if(this.width) {
+        _videoEl.attr("width", this.width);
+    }
+    if(this.height) {
+        _videoEl.attr("height", this.height);
+    }
+    this.$.append(_videoEl);
+    var _popcorn = Popcorn("#" + _tmpId);
+
+    // Binding functions to Popcorn
+    
+    this.media.getCurrentTime = function() {
+        return new IriSP.Model.Time(1000*_popcorn.currentTime());
+    }
+    this.media.getVolume = function() {
+        return _popcorn.volume();
+    }
+    this.media.getPaused = function() {
+        return _popcorn.media.paused;
+    }
+    this.media.getMuted = function() {
+        return _popcorn.muted();
+    }
+    this.media.setCurrentTime = function(_milliseconds) {
+        return _popcorn.currentTime(_milliseconds / 1000);
+    }
+    this.media.setVolume = function(_vol) {
+        return _popcorn.volume(_vol);
+    }
+    this.media.mute = function() {
+        return _popcorn.muted(true);
+    }
+    this.media.unmute = function() {
+        return _popcorn.muted(false);
+    }
+    this.media.play = function() {
+        return _popcorn.play();
+    }
+    this.media.pause = function() {
+        return _popcorn.pause();
+    }
+    
+    // Binding Popcorn events to media
+    
+    var _media = this.media;
+    _popcorn.on("timeupdate", function() {
+        _media.trigger("timeupdate", _media.getCurrentTime());
+    });
+    
+    function simpleEventBind(_eventname) {
+        _popcorn.on(_eventname, function() {
+            _media.trigger(_eventname);
+        });
+    }
+    
+    simpleEventBind("play");
+    simpleEventBind("pause");
+    simpleEventBind("seeked");
+    simpleEventBind("loadedmetadata");
+    simpleEventBind("volumechange");
+    
+}
\ No newline at end of file
--- a/test/jwplayer.htm	Mon Sep 17 00:17:06 2012 +0900
+++ b/test/jwplayer.htm	Mon Sep 17 22:44:59 2012 +0900
@@ -23,65 +23,62 @@
 //        url: 'http://ldt.iri.centrepompidou.fr/ldtplatform/ldt/cljson/id/5a893570-ca73-11e1-9443-00145ea4a2be?callback=?',
         format: 'ldt'
     };
-    var _config = {            
-        gui: {
-            width : 550,
-            container : 'LdtPlayer',
-            default_options: {
+    var _config = {
+        width : 550,
+        container : 'LdtPlayer',
+        default_options: {
+            metadata: _metadata
+        },
+        css : 'metadataplayer/LdtPlayer-core.css',
+        widgets: [
+            {
+                type: "JwpPlayer",
+                live: true, 
+                height: 350, 
+                width: 550, 
+                provider: "rtmp",
+                streamer: function(_url) {
+                    var _matches = _url.match(/^[^\/]+\/\/[^\/]+\/[^\/]+\//);
+                    if (_matches) {
+                        return _matches[0];
+                    } else {
+                        return _url;
+                    }
+                },
                 metadata: _metadata
             },
-            css : 'metadataplayer/LdtPlayer-core.css',
-            widgets: [
-                { type: "Slider" },
-                { type: "Controller" },
-                { type: "Polemic" },
-                { type: "Segments" },
-                { type: "Slice" },
-                {
-                    type: "Arrow",
-                    base_height: 4
-                },
-                { type: "Annotation" },
-                {
-                    type: "CreateAnnotation",
-                    api_endpoint_template: "post-test.php",
-                    creator_name: "Metadataplayer",
-                    creator_avatar: "https://si0.twimg.com/sticky/default_profile_images/default_profile_1_normal.png",
-                    tag_titles: ["#amateur", "#digital-humanities"]
-                },
-                { type: "Tweet" },
-                {
-                    type: "Tagger",
-                    api_endpoint: "post-test.php"
-                },
-                {
-                    type: "Tagcloud"
-                },
-                {
-                    type: "AnnotationsList",
-                    container: "AnnotationsListContainer",
-                    default_thumbnail : "http://ldt.iri.centrepompidou.fr/static/site/ldt/css/imgs/video_sequence.png"
-                },
-                { type: "Mediafragment"}
-            ]
-        },
-        player:{
-            type:'auto',
-            live: true, 
-            height: 350, 
-            width: 550, 
-            provider: "rtmp",
-            streamer: function(_url) {
-                var _matches = _url.match(/^[^\/]+\/\/[^\/]+\/[^\/]+\//);
-                if (_matches) {
-                    return _matches[0];
-                } else {
-                    return _url;
-                }
+            { type: "Slider" },
+            { type: "Controller" },
+            { type: "Polemic" },
+            { type: "Segments" },
+            { type: "Slice" },
+            {
+                type: "Arrow",
+                base_height: 4
             },
-            //autostart: true,
-            metadata: _metadata
-        }
+            { type: "Annotation" },
+            {
+                type: "CreateAnnotation",
+                api_endpoint_template: "post-test.php",
+                creator_name: "Metadataplayer",
+                creator_avatar: "https://si0.twimg.com/sticky/default_profile_images/default_profile_1_normal.png",
+                tag_titles: ["#amateur", "#digital-humanities"]
+            },
+            { type: "Tweet" },
+            {
+                type: "Tagger",
+                api_endpoint: "post-test.php"
+            },
+            {
+                type: "Tagcloud"
+            },
+            {
+                type: "AnnotationsList",
+                container: "AnnotationsListContainer",
+                default_thumbnail : "http://ldt.iri.centrepompidou.fr/static/site/ldt/css/imgs/video_sequence.png"
+            },
+            { type: "Mediafragment"}
+        ]
     };
     
     var _myPlayer = new IriSP.Metadataplayer(_config);
--- a/test/oggvideo.htm	Mon Sep 17 00:17:06 2012 +0900
+++ b/test/oggvideo.htm	Mon Sep 17 22:44:59 2012 +0900
@@ -21,43 +21,32 @@
     url: "json/ldt-ogv.json",
     format: 'ldt'
 };
-var _config = {            
-    gui: {
-        width : 620,
-        container : 'LdtPlayer',
-        default_options: {
-            metadata: _metadata
+var _config = {
+    width : 620,
+    container : 'LdtPlayer',
+    default_options: {
+        metadata: _metadata
+    },
+    css : 'metadataplayer/LdtPlayer-core.css',
+    widgets: [
+        { type: "PopcornPlayer" },
+        { type: "Sparkline" },
+        { type: "Slider" },
+        { type: "Controller" },
+        { type: "Polemic" },
+        { type: "Segments" },
+        { type: "Slice" },
+        { type: "Arrow" },
+        { type: "Annotation" },
+        { type: "CreateAnnotation" },
+        { type: "Tweet" },
+        { type: "Tagcloud" },
+        {
+            type: "AnnotationsList",
+            container: "AnnotationsListContainer"
         },
-        css : 'metadataplayer/LdtPlayer-core.css',
-        widgets: [
-            { type: "PopcornPlayer"},
-            { type: "Sparkline" },
-            { type: "Slider" },
-            { type: "Controller" },
-            { type: "Polemic" },
-            { type: "Segments" },
-            { type: "Slice" },
-            { type: "Arrow" },
-            { type: "Annotation" },
-            { type: "CreateAnnotation" },
-            { type: "Tweet" },
-            { type: "Tagcloud" },
-            {
-                type: "AnnotationsList",
-                container: "AnnotationsListContainer"
-            },
-            { type: "Mediafragment"}
-        ]
-    },
-    player:{
-        type:'auto',
-        live: true, 
-        height: 350, 
-        width: 620, 
-        provider: "rtmp",
-        autostart: true,
-        metadata: _metadata
-    }
+        { type: "Mediafragment"}
+    ]
 };
 _myPlayer = new IriSP.Metadataplayer(_config);
         </script>