client/player/js/LdtPlayer.js
changeset 51 2d6866072851
child 57 3a3c15c462f8
equal deleted inserted replaced
50:1ecfe4720da7 51:2d6866072851
       
     1 /* ----------------------------------------------------------------
       
     2    ----------------------------------------------------------------
       
     3    ----------------------------------------------------------------
       
     4    
       
     5 	LDTPlayer is created by http://www.iri.centrepompidou.fr
       
     6 	2010-06-14 - version 0.07
       
     7 	
       
     8 	init By Samuel Huron < samuel.huron (at) cybunk (dot) com >
       
     9 	
       
    10 	
       
    11    ----------------------------------------------------------------
       
    12 */
       
    13 
       
    14 
       
    15 
       
    16 
       
    17 /* ----------------------------------------------------------------
       
    18    ----------------------------------------------------------------
       
    19  INTERFACE : SLIDER ( CONTROL BAR ) | BUTTON ()   */
       
    20 
       
    21 
       
    22 	function createInterface (width,height,duration){
       
    23 		$jIRI(function() {
       
    24 		
       
    25 			$jIRI("#Annotations").width(width-(78*2));
       
    26 			$jIRI("#ShowAnnotation").width(width-10);
       
    27 			$jIRI("#controlerLdt").width(width);
       
    28 			$jIRI("#Ldtplayer1").attr("z-index","100");
       
    29 			
       
    30 			 $jIRI("#ShowAnnotation").click(function () { 
       
    31 				 $jIRI(this).slideUp(); 
       
    32 			});
       
    33 
       
    34 			var LdtpPlayerY = $jIRI("#ldtPlaceHolder").attr("top");
       
    35 			var LdtpPlayerX = $jIRI("#ldtPlaceHolder").attr("left");
       
    36 			
       
    37 			//alert(LdtpPlayerY+" | "+LdtpPlayerX);
       
    38 			//$jIRI("#ShowAnnotation").attr("position","absolute");
       
    39 			/*$jIRI("#ShowAnnotation").attr("top",0);
       
    40 			$jIRI("#ShowAnnotation").attr("left",0);*/
       
    41 			
       
    42 			//$jIRI("#slider-range-min").roll
       
    43 			$jIRI("#slider-range-min").slider({ //range: "min",
       
    44 				value: 0,
       
    45 				min: 1,
       
    46 				max: duration/1000,//1:54:52.66 = 3600+3240+
       
    47 				step: 0.1,
       
    48 				slide: function(event, ui) {
       
    49 					
       
    50 					//$jIRI("#amount").val(ui.value+" s");
       
    51 					player.sendEvent('SEEK', ui.value)
       
    52 					//player.sendEvent('PAUSE')
       
    53 				}
       
    54 			});
       
    55 			$jIRI("#amount").val($jIRI("#slider-range-min").slider("value")+" s");
       
    56 			
       
    57 			$jIRI(".ldtControl1 button:first").button({
       
    58 				icons: {
       
    59 					primary: 'ui-icon-play'
       
    60 				},
       
    61 				text: false
       
    62 			}).next().button({
       
    63 				icons: {
       
    64 					primary: 'ui-icon-seek-next'
       
    65 				},
       
    66 				 text: false
       
    67 			});
       
    68 			
       
    69 			$jIRI(".ldtControl2 button:first").button({
       
    70 				icons: {
       
    71 					primary: 'ui-icon-newwin'//,
       
    72 					//secondary: 'ui-icon-volume-off'
       
    73 				},
       
    74 				text: false
       
    75 			}).next().button({
       
    76 				icons: {
       
    77 					primary: 'ui-icon-volume-on'
       
    78 				},
       
    79 				 text: false
       
    80 			});
       
    81 		
       
    82 		});	
       
    83 	}
       
    84 
       
    85 /* ----------------------------------------------------------------
       
    86    ----------------------------------------------------------------
       
    87  CREER JW PLAYER  creation + listener */
       
    88 
       
    89 
       
    90 	var currentPosition = 0; 
       
    91 	var currentVolume   = 50; 
       
    92 	var player 			= null;
       
    93 	
       
    94 	function playerReady(thePlayer) {
       
    95 		//alert("ready");
       
    96 		player = window.document[thePlayer.id];
       
    97 		addListeners();	
       
    98 	}
       
    99 
       
   100 	function addListeners() {
       
   101 		if (player) { 
       
   102 			player.addModelListener("TIME", "positionListener");
       
   103 			player.addControllerListener("VOLUME", "volumeListener");
       
   104 			player.addPlayPauseListener("PLAY", "state");
       
   105 		} else {
       
   106 			setTimeout("addListeners()",100);
       
   107 		}
       
   108 
       
   109 		// et changer les boutons
       
   110 	}
       
   111 	
       
   112 	//function 
       
   113 
       
   114 	function addPlayPauseListener(obj) { 
       
   115 		if(obj){
       
   116 			$jIRI(".control1 button:first").button({
       
   117 				icons: {
       
   118 					primary: 'ui-icon-pause'
       
   119 				},
       
   120 				text: false
       
   121 			});
       
   122 		}else{
       
   123 			$jIRI(".control1 button:first").button({
       
   124 				icons: {
       
   125 					primary: 'ui-icon-play'
       
   126 				},
       
   127 				text: false
       
   128 			});
       
   129 		}
       
   130 	}
       
   131 	
       
   132 	function positionListener(obj) { 
       
   133 		currentPosition = obj.position; 
       
   134 		var tmp = document.getElementById("posit");
       
   135 		if (tmp) { tmp.innerHTML = "position: " + currentPosition; }
       
   136 		$jIRI("#slider-range-min").slider("value", obj.position);
       
   137 		$jIRI("#amount").val(obj.position+" s");
       
   138 		// afficher annotation 
       
   139 		
       
   140 		MyLdt.checkTime(currentPosition);
       
   141 	}
       
   142 
       
   143 	function volumeListener(obj) { 
       
   144 		currentVolume = obj.percentage; 
       
   145 		var tmp = document.getElementById("vol");
       
   146 		if (tmp) { tmp.innerHTML = "volume: " + currentVolume; }
       
   147 	}
       
   148 
       
   149 	function createPlayer(width,height,url,duration,streamerPath,MySwfPath) {
       
   150 	
       
   151 		myUrlFragment = url.split(streamerPath);
       
   152 		file = myUrlFragment[1];
       
   153 		//alert(url+" = "+streamerPath+" + "+file);
       
   154 		streamer = streamerPath;
       
   155 		//alert(" StreamerPath : "+streamer+" - "+file);
       
   156 		//alert(" SwfPath : "+MySwfPath);
       
   157 		
       
   158 		var flashvars = {
       
   159 			streamer:streamer,
       
   160 			file:file, 
       
   161 			//live:"true",
       
   162 			autostart:"true",
       
   163 			controlbar:"none"
       
   164 		}
       
   165 
       
   166 		var params = {
       
   167 			allowfullscreen:"true", 
       
   168 			allowscriptaccess:"always",
       
   169 			wmode:"transparent"
       
   170 		}
       
   171 
       
   172 		var attributes = {
       
   173 			id:"Ldtplayer1",  
       
   174 			name:"Ldtplayer1"
       
   175 		}
       
   176 
       
   177 		swfobject.embedSWF(MySwfPath, "ldtPlaceHolder", width, height, "9.0.115", false, flashvars, params, attributes);
       
   178 	}
       
   179 	
       
   180 
       
   181 
       
   182 
       
   183 
       
   184 
       
   185 /* ----------------------------------------------------------------
       
   186    ----------------------------------------------------------------
       
   187 
       
   188 LOAD JSON AND PARSE IT
       
   189 */
       
   190 	
       
   191 
       
   192 	var MyLdt;
       
   193 	var Durration;
       
   194 	var playerLdtWidth;
       
   195 	var playerLdtHeight;
       
   196 	
       
   197 	function loadJson (width,height,urlJson,MySwfPath){
       
   198 		
       
   199 		playerLdtWidth=width;
       
   200 		playerLdtHeight=height;
       
   201 		
       
   202 		$jIRI.ajax({
       
   203 					  dataType: 'jsonp',
       
   204 					  url:urlJson,//+"?callback=callbackLdts",
       
   205 					  //jsonpCallback:callbackLdts,
       
   206 					  success: function(json){
       
   207 						
       
   208 						//eval(json);
       
   209 						//alert("callback LDTS");
       
   210 						/* START PARSING ----------------------- */
       
   211 						/* metas , medias , annotation-types , annotations , lists , tags , views */
       
   212 						/* # fonction avec 1 seul  media et 1 seul annotation type  code a cleaner */
       
   213 						/* # créer le player 				   */
       
   214 						//$jIRI.each(json.medias, function(i,item) {
       
   215 						//});
       
   216 						$jIRI("<div></div>").appendTo("#output");
       
   217 						MyMedia = new  Media(json.medias[0].id,json.medias[0].href,json.medias[0]["meta"]["dc:duration"],json.medias[0]['dc:title'],json.medias[0]['dc:description']);
       
   218 						//alert(" MySwfPath : "+MySwfPath);
       
   219 						MyMedia.createPlayer(playerLdtWidth,playerLdtHeight,json.medias[0]["meta"]["item"]["value"],MySwfPath);
       
   220 						//alert("success loading ! "+json.medias[0]["meta"]["dc:duration"]+ " | " +json.medias[0]["meta"]["item"]["value"]);
       
   221 						
       
   222 						/* # créer lignes 				   */
       
   223 						/*$jIRI.each(json['annotation-types'], function(i,item) {
       
   224 						});*/	
       
   225 						MyLdt = new Ligne (json['annotation-types'][0].id,json['annotation-types'][0]['dc:title'],json['annotation-types'][0]['dc:description'],json.medias[0]["meta"]["dc:duration"]);
       
   226 						//alert("duration : "+json.medias[0]["dc:duration"]);
       
   227 						
       
   228 						/* # créer les annotations 				   */
       
   229 						$jIRI.each(json.annotations, function(i,item) {
       
   230 
       
   231 							MyLdt.addAnnotation(
       
   232 										item.id,
       
   233 										item.begin,
       
   234 										item.end,
       
   235 										item.media,
       
   236 										item.content.title,
       
   237 										item.content.description,
       
   238 										item.content.color);
       
   239 						
       
   240 						});	
       
   241 						$jIRI.each(json.lists, function(i,item) {
       
   242 							trace("lists","");
       
   243 						});		
       
   244 						$jIRI.each(json.tags, function(i,item) {
       
   245 							trace("tags","");
       
   246 						});	
       
   247 						$jIRI.each(json.views, function(i,item) {
       
   248 							trace("views","");
       
   249 						});	
       
   250 						/* END PARSING ----------------------- */
       
   251 						
       
   252 										
       
   253 					}
       
   254 					,error: function(data){
       
   255 						  alert("ERROR : "+data);
       
   256 					}		
       
   257 				  });	
       
   258 	}
       
   259 
       
   260 	function callbackLdts(json){
       
   261 		
       
   262 	}
       
   263 	
       
   264 	function trace (msg,value){
       
   265 		$jIRI("<div>"+msg+" : "+value+"</div>").appendTo("#output");
       
   266 	}
       
   267 
       
   268 
       
   269 	
       
   270 	
       
   271 /* ----------------------------------------------------------------
       
   272    ----------------------------------------------------------------
       
   273 INIT player LDT  
       
   274 */
       
   275 
       
   276 	function playerLdt (width,height,file,divId,MySwfPath){
       
   277 		
       
   278 			$jIRI("#"+divId).append("<div id=\"ldtShow\">\n	<div id=\"ShowAnnotation\" class=\"demo\" >\n			<div id=\"ldtSaTitle\"></div>\n			<div id=\"ldtSaDescription\"></div>\n		</div>		<div id=\"ldtPlaceHolder\">\n			<a href=\"http://www.adobe.com/go/getflashplayer\">Get flash</a> to see this player	\n		</div>\n	</div>\n	<div id=\"controlerLdt\" class=\"demo\">\n		<div class=\"ldtControl1\" >\n			<button id=\"ldtCtrlPlay\" onclick=\"player.sendEvent('PLAY')\">Play</button>\n			<button id=\"ldtCtrlNext\" onclick=\"player.sendEvent('SEEK', currentPosition+10)\">next</button>\n		</div>\n		<div id=\"Annotations\" class=\"ui-slider\">\n			<div id=\"slider-range-min\"></div>\n		</div>\n		<div class=\"ldtControl2\">\n			<button id=\"ldtCtrlScreen\" onclick=\"player.fullscreen('true')\">Enlarge</button>\n			<button id=\"ldtCtrlSound\" onclick=\"player.sendEvent('MUTE')\">Sound</button>\n		</div>\n	</div><div class='cleaner'>&nbsp;</div>");
       
   279 			loadJson(width,height,file,MySwfPath);
       
   280 	}
       
   281 	
       
   282 	
       
   283 	
       
   284 
       
   285 
       
   286 /* ----------------------------------------------------------------
       
   287    ----------------------------------------------------------------
       
   288  API player */
       
   289 
       
   290 
       
   291 	function APIplayer (){
       
   292 
       
   293 	}
       
   294 	
       
   295 
       
   296 
       
   297 /* ----------------------------------------------------------------
       
   298    ----------------------------------------------------------------
       
   299 	Class Media
       
   300 
       
   301 
       
   302 		"http://advene.liris.cnrs.fr/ns/frame_of_reference/ms":"o=0",
       
   303 		"id":"kia_closeup",
       
   304 		"url":"D:/Thibaut/Outils_techno/IRI-LignesDeTemps/media/video/kia_closeup_BQ.flv",
       
   305 		"dc:creator":"tcavalie",
       
   306 		"dc:created":"2010-05-04T00:00:00",
       
   307 		"dc:contributor":"tcavalie",
       
   308 		"dc:modified":"2010-05-04T00:00:00",
       
   309 		"dc:creator.contents":"Abbas Kiarostami",
       
   310 		"dc:created.contents":"1990",
       
   311 		"dc:title":"Close Up is a very very long title",
       
   312 		"dc:description":"Analyse de Close Up",
       
   313 		"dc:duration":"689266"
       
   314 	*/
       
   315 	function Media (id,url,duration,title,description){
       
   316 		this.id 		 = id;
       
   317 		this.url 		 = url;
       
   318 		this.title 		 = title;
       
   319 		this.description = description;
       
   320 		this.duration 	 = duration;
       
   321 
       
   322 		this.lignes = new Array();
       
   323 		this.updatePlayer = updatePlayerMedia;
       
   324 		this.getDuration = getMediaDuration;
       
   325 		this.createPlayer = createPlayerMedia;
       
   326 		
       
   327 		trace("Media ID :",id);
       
   328 		trace("Media URL :",this.url);
       
   329 		trace("- content : color",url);
       
   330 		trace("- content : audio",title);
       
   331 	}
       
   332 	function createPlayerMedia(width,height,MyStreamer,MySwfPath){
       
   333 		//alert("create swfpath : "+MySwfPath+" my streame : "+MyStreamer);
       
   334 		createPlayer(width,height,this.url,this.duration,MyStreamer,MySwfPath);
       
   335 		createInterface(width,height,this.duration);
       
   336 	}
       
   337 	function updatePlayerMedia(){
       
   338 		
       
   339 	}
       
   340 	function getMediaDuration(){
       
   341 		return (this.duration);
       
   342 	}
       
   343 	function getMediaTitle(){
       
   344 		return (this.title);
       
   345 	}
       
   346 	
       
   347 
       
   348 /* ----------------------------------------------------------------
       
   349    ----------------------------------------------------------------
       
   350  Class Ligne (annotationType) 
       
   351 	
       
   352 		"id":"dp_1",
       
   353 		"dc:creator":"tcavalie",
       
   354 		"dc:created":"2010-04-04T19:09:44",
       
   355 		"dc:contributor":"perso",
       
   356 		"dc:modified":"15/2/2008",
       
   357 		"dc:title":"dqsdkljfh qklsdhf very very very long",
       
   358 		"dc:description":"sdfg sdfg sdfg sdfg"
       
   359 	*/
       
   360 	function Ligne (){
       
   361 		this.id 			= id;
       
   362 		this.title 			= title;
       
   363 		this.description 	= description;
       
   364 		this.annotations 	= new Array();
       
   365 		this.addAnnotation  = addAnnotationligne;
       
   366 		this.clickAnnotation= onClickLigneAnnotation;
       
   367 		this.checkTime 		= checkTimeLigne;
       
   368 	}
       
   369 	
       
   370 	function Ligne (id,title,description,duration){
       
   371 		this.id 		 = id;
       
   372 		this.title 		 = title;
       
   373 		this.description = description;
       
   374 		//
       
   375 		this.annotations = new Array();
       
   376 		this.addAnnotation = addLigneAnnotation;
       
   377 		this.checkTime 	= checkTimeLigne;
       
   378 		this.duration = duration;
       
   379 		trace("LIGNE  ","créer ");
       
   380 	}
       
   381 	
       
   382 	function addLigneAnnotation(id,begin,end,media,title,description,color){
       
   383 		var myAnnotation = new Annotation(id,begin,end,media,title,description,color,this.duration);
       
   384 		this.annotations.push(myAnnotation);
       
   385 		trace("LIGNE  ","add annotation ");
       
   386 	}
       
   387 	
       
   388 	function onClickLigneAnnotation(id){
       
   389 		player.sendEvent('SEEK', this.start);
       
   390 	}
       
   391 	
       
   392 	function searchLigneAnnotation(id){
       
   393 		/*for (){
       
   394 		}*/
       
   395 	}
       
   396 	
       
   397 	function listAnnotations(){
       
   398 	
       
   399 	}
       
   400 	
       
   401 	function checkTimeLigne(time){
       
   402 		var annotationTempo;
       
   403 		for (var i=0; i < this.annotations.length; ++i){
       
   404 			var annotationTempo = this.annotations[i];
       
   405 			//trace("check... ",time+" = "+annotationTempo.begin+" -- "+annotationTempo.end);
       
   406 			//if (time>annotationTempo.begin){
       
   407 			if (time>annotationTempo.begin/1000 && time<annotationTempo.end/1000){
       
   408 				//trace("check ",annotationTempo.begin+" "+annotationTempo.end +" "+annotationTempo.title);
       
   409 				$jIRI("#ldtSaTitle").text(annotationTempo.title);
       
   410 				$jIRI("#ldtSaDescription").text(annotationTempo.description);
       
   411 				break;
       
   412 			} 
       
   413 		}
       
   414 	}
       
   415 	
       
   416 
       
   417 
       
   418 /* ----------------------------------------------------------------
       
   419    ----------------------------------------------------------------
       
   420   CLASSE Annotation 
       
   421 
       
   422 
       
   423 		"begin":"767",
       
   424 		"end":"785",
       
   425 		"id":"dp_1_sp_3",
       
   426 		"media":"kia_closeup",
       
   427 		"content": {
       
   428 						"mimetype":"application/x-ldt-structured",
       
   429 						"title":"mon titre",
       
   430 						"description":"ma description en &lt;b&gt;gras&lt;/b&gt; .",
       
   431 						"color":"16763904",
       
   432 						"audio":{"src":"","mimetype":"audio/mp3","href":""}
       
   433 					},
       
   434 		"meta":
       
   435 				{
       
   436 					"id-ref":"dp_1",
       
   437 					"dc:creator":"tcavalie",
       
   438 					"dc:created":"2010-04-04T19:09:44",
       
   439 					"dc:contributor":"perso",
       
   440 					"dc:modified":"9/10/2007"
       
   441 				}
       
   442 	*/
       
   443 	
       
   444 	function Annotation (){
       
   445 		this.id 			= null;
       
   446 		this.begin 			= null;
       
   447 		this.end 			= null;
       
   448 		this.media 			= null;
       
   449 		this.description	= null;
       
   450 		this.title 			= null;
       
   451 		this.color 			= null;
       
   452 		this.onRollOver 	= onRollOverAnnotation;
       
   453 		this.onClick 		= onClickAnnotation;
       
   454 		this.toolTip 		= rollOverAnnotation;
       
   455 		this.draw 			= drawAnnotation;
       
   456 		trace("annotation ","réussi")
       
   457 	}
       
   458 	
       
   459 	function Annotation (id,begin,end,media,title,description,color,duration){
       
   460 		this.id 			= id;
       
   461 		this.begin 			= begin;
       
   462 		this.end 			= end;
       
   463 		this.media 			= media;
       
   464 		this.description 	= description;
       
   465 		this.title 			= title;
       
   466 		this.color 			= title;
       
   467 		this.duration		= duration;
       
   468 		//
       
   469 		this.onRollOver 	= onRollOverAnnotation;
       
   470 		//this.onClick 		= onClickAnnotation;
       
   471 		this.toolTip 		= tootTipAnnotation;
       
   472 		this.draw 			= drawAnnotation;
       
   473 		//this.show 			= showAnnotationNotice;
       
   474 		// draw it 
       
   475 		this.draw();
       
   476 		
       
   477 		//
       
   478 		trace("Annotation created : ",id);
       
   479 	}
       
   480 	
       
   481 	function drawAnnotation (){
       
   482 		//alert (this.duration);
       
   483 		startPourcent = timeToPourcent(this.begin,this.duration); // temps du média 
       
   484 		endPourcent = timeToPourcent(this.end,this.duration)-startPourcent;
       
   485 				
       
   486 		$AnnotationTemplate = "<div title='"+this.title+"' id='"+this.id+"'  class='ui-slider-range ui-slider-range-min ui-widget-header iri-chapter' width='100%' style='left:"+startPourcent+"%; width:"+endPourcent+"%; padding-top:15px; border-left:solid 1px #aaaaaa; border-right:solid 1px #aaaaaa;' onclick=\"player.sendEvent('SEEK', '"+Math.round(this.begin/1000)+"');$jIRI('#ShowAnnotation').slideDown().delay(5000).slideUp();\"  ></div> ";
       
   487 		
       
   488 
       
   489 		
       
   490 		$toolTipTemplate = "<div class='tooltip'>"
       
   491 							+"<div class='title'>"+this.title+"</div>"
       
   492 							+"<div class='time'>"+this.begin+" : "+this.end+"</div>"
       
   493 							+"<div class='description'>"+this.description+"</div>"
       
   494 							+"</div>";
       
   495 		
       
   496 		
       
   497 		$jIRI("<div>"+$AnnotationTemplate+"</div>").appendTo("#Annotations");
       
   498 		$jIRI("#"+this.id).tooltip({ effect: 'slide'});
       
   499 
       
   500 		trace(" ### ","ADD ANOTATION : "+this.begin+" "+this.end+" "+this.title+" | "+startPourcent+" | "+endPourcent+" | duration = "+this.duration);
       
   501 	}
       
   502 	
       
   503 	function tootTipAnnotation() {
       
   504 		// 1 chercher le div correspondant
       
   505 		// 2 y mettre les information
       
   506 		return this.color + ' ' + this.type + ' apple';
       
   507 	}
       
   508 	
       
   509 	function onRollOverAnnotation(){
       
   510 		this.tootTip();
       
   511 	}
       
   512 		
       
   513 	function timeToPourcent(time,timetotal){
       
   514 		return (parseInt(Math.round(time/timetotal*100)));
       
   515 	}
       
   516 		
       
   517 		
       
   518 /* ----------------------------------------------------------------
       
   519    ----------------------------------------------------------------
       
   520 	Class tracess */
       
   521 	
       
   522 	function Tracer (){
       
   523 		
       
   524 	}
       
   525 	
       
   526 	function addTrace(){
       
   527 		
       
   528 	}
       
   529 	
       
   530 	
       
   531