src/js/init.js
author hamidouk
Mon, 24 Oct 2011 16:51:22 +0200
branchpopcorn-port
changeset 127 3ce493c93d6c
parent 123 58bb8ccea9a8
child 129 296d9ddf9cc1
permissions -rw-r--r--
added tests for init.js.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
123
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
     1
/* init.js - initialization and configuration of Popcorn and the widgets
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
     2
exemple json configuration:
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
     3
  
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
     4
  var config = {						
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
     5
						gui:{
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
     6
							width:650,
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
     7
							height:480,							
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
     8
							container:'LdtPlayer',
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
     9
							css:'../../src/css/LdtPlayer.css',
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    10
              widgets: [
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    11
                {type: "IriSP.PlayerWidget", // please note that type refers directly to the constructor of the widget.
123
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    12
                 metadata:{
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    13
                  format:'cinelab',
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    14
                  src:'test.json',
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    15
                  load:'json'}
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    16
                },
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    17
               {type: "IriSP.SegmentsWidget", 
123
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    18
                 metadata:{
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    19
                  format:'cinelab',
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    20
                  src:'test.json',
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    21
                  load:'json'}
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    22
                },
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    23
               {type: "IriSP.AnnotationsWidget",                
123
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    24
                 metadata:{
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    25
                  format:'cinelab',
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    26
                  src:'test.json',
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    27
                  load:'json'}
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    28
                },
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    29
              ]
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    30
						player:{
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    31
							type:'jwplayer', // player type
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    32
              container: '#PopcornContainer'
123
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    33
              // the rest is player-dependent configuration options.
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    34
              file : "video/franceculture/franceculture_retourdudimanche20100620.flv", 
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    35
              streamer: "rtmp://media.iri.centrepompidou.fr/ddc_player/", 
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    36
              flashplayer : '../libs/player.swf',
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    37
              live: true, 
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    38
              "controlbar.position" : "none", 
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    39
              height: 300, 
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    40
              width: 200, 
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    41
              provider: "rtmp" 
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    42
            }
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    43
	};
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    44
 */
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    45
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    46
IriSP.configurePopcorn = function (options) {
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    47
    var pop;
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    48
    
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    49
    switch(options.type) {
123
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    50
      /*
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    51
        todo : dynamically create the div/video tag which
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    52
        will contain the video.
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    53
      */
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    54
      case "html5":
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    55
           pop = Popcorn(options.container);
123
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    56
        break;
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    57
        
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    58
      case "jwplayer":
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    59
          var opts = IriSP.jQuery.extend({}, options);
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    60
          delete opts.container;
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    61
          pop = Popcorn.jwplayer(options.container, "", opts);
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    62
        break;
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    63
        
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    64
      default:
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    65
        pop = undefined;
123
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    66
    };
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    67
    
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    68
    return pop;
123
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    69
};
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    70
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    71
IriSP.configureWidgets = function (popcornInstance, guiOptions) {
123
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    72
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    73
  var dt = new IriSP.DataLoader();
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    74
  var serialFactory = new IriSP.SerializerFactory(dt);
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    75
  
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    76
  var params = {width: guiOptions.width, height: guiOptions.height};
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    77
  var lay = new IriSP.LayoutManager(params);
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    78
  
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    79
  var ret_widgets = [];
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    80
  
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    81
  for (index in guiOptions.widgets) {    
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    82
    var widget = guiOptions.widgets[index];
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    83
    var container = lay.createDiv();
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    84
        
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    85
    var arr = IriSP.jQuery.extend({}, widget);
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    86
    arr.container = container;
123
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    87
    
127
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    88
    var serializer = serialFactory.getSerializer(widget.metadata);
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    89
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    90
    // instantiate the object passed as a string
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    91
    var widget = new IriSP[widget.type](popcornInstance, widget, serializer);    
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    92
    serializer.sync(function() { widget.draw() });
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    93
    ret_widgets.push(widget);
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    94
  };
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    95
  
3ce493c93d6c added tests for init.js.
hamidouk
parents: 123
diff changeset
    96
  return ret_widgets;
123
58bb8ccea9a8 added a file for the init routines.
hamidouk
parents:
diff changeset
    97
};