PageRenderTime 22ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/_plugins_/player/branches/lm_v1/player_enclosure.js

https://bitbucket.org/pombredanne/spip-zone-treemap
JavaScript | 441 lines | 306 code | 60 blank | 75 comment | 27 complexity | a6d8ed132fa74fed59d351f6246df1e1 MD5 | raw file
  1. /*
  2. Appelee par le body onload, cette fonction affiche les players mp3/flv et genere les playlistes associees
  3. Auteur : BoOz <booz CHEZ rezo POINT net>
  4. Licence : GNU/GPL
  5. compatibilite firefox par Vincent Ramos <www-lansargues CHEZ kailaasa POINT net> et erational <http://www.erational.org>
  6. *
  7. * Fonctionne avec jQuery.
  8. * sounmanager2 : http://www.schillmania.com/projects/soundmanager2/
  9. **/
  10. var track_index = 0;
  11. live_track = 'stop' ;
  12. live_video = 'stop' ;
  13. isVideoPlaying = false ;
  14. videoPause = false ;
  15. isPlaying = false ;
  16. soundManager.consoleOnly = true;
  17. soundManager.debugMode = false;
  18. var seljQ = '@';
  19. if (jQuery.fn.jquery>="1.3.0")
  20. seljQ='';
  21. jQuery(document).ready(function(){
  22. //lecteur_debug();
  23. lecteur_multimedia_init();
  24. });
  25. function lecteur_multimedia_init(){
  26. //tableau des fichiers multimedia de la page
  27. mp3Array = new Array();
  28. mp3Titles = new Array();
  29. flvArray = new Array();
  30. flvTitles = new Array();
  31. var aff= jQuery("a["+seljQ+"rel='enclosure']["+seljQ+"href$=mp3]").size();
  32. // lister les mp3 de la page
  33. jQuery("a["+seljQ+"rel='enclosure']["+seljQ+"href$=mp3]").each(
  34. function(i) {
  35. // we store mp3 links in an array
  36. mp3Array.push(this.href);
  37. mp3Titles.push(jQuery(this).html());
  38. //demarrer le lecteur lors d'un click
  39. jQuery(this).click(
  40. function(e){
  41. e.preventDefault();
  42. player_play(i);
  43. jQuery("#bouton_play").attr('src',DIR_PLUGIN_PLAYER + 'skins/blogo/pause.png');
  44. }
  45. );
  46. // activer le click sur un parent de class "play_"
  47. if(jQuery(this).parent().attr("class"))
  48. if(jQuery(this).parent().attr("class").split(" ").contains("play_"))
  49. jQuery(this).parent().click(
  50. function(e){
  51. player_play(i);
  52. jQuery("#bouton_play").attr('src',DIR_PLUGIN_PLAYER + 'skins/blogo/pause.png');
  53. }
  54. );
  55. // ajouter un bouton "play" devant les liens hors player -
  56. //a passer en .ajoute_musicplayer()
  57. //jQuery(this).before('<span class="play_">play</span>&nbsp;');
  58. jQuery(this).before('<span class="play_"><img src="' + image_play + '"/></span>&nbsp;');
  59. }
  60. );
  61. jQuery("a["+seljQ+"rel='video']").each(
  62. function(i) {
  63. // we store flv links in an array
  64. flvArray.push(this.href);
  65. flvTitles.push(jQuery(this).html());
  66. //demarrer le lecteur lors d'un click
  67. jQuery(this).click(
  68. function(e){
  69. e.preventDefault();
  70. video_play(i);
  71. // jQuery("#now_playing").html(jQuery(this).html());
  72. }
  73. );
  74. }
  75. );
  76. // css playliste
  77. // du player
  78. jQuery(".playliste").find("span").remove(); // traiter a par le player
  79. jQuery(".playliste li").hover(function(){
  80. jQuery(this).addClass("over");
  81. },function(){
  82. jQuery(this).removeClass("over");
  83. });
  84. // liens mp3 hors player avec bouton
  85. // toggle play / pause
  86. jQuery("span.play_").each(
  87. function(i) {
  88. jQuery(this).toggle(
  89. function(e){
  90. if(live_track !=='stop'){
  91. player_stop();
  92. }else{
  93. player_play(i) ;
  94. jQuery(this).html("<img src='" + image_pause + "'/>").addClass("play_on");
  95. // i c pas forcemment bon si t'as un player avant le lien cf plus bas
  96. }
  97. },function(e){
  98. player_stop(); // ou pause ?
  99. }
  100. );
  101. }
  102. );
  103. // le bouton play/pause du player
  104. jQuery('#bouton_play').click(function(e){
  105. //console.log(isPlaying);
  106. if(!isPlaying){
  107. jQuery(this).attr('src',DIR_PLUGIN_PLAYER + 'skins/blogo/pause.png');
  108. if(live_track =='stop') {
  109. player_play(0) ;
  110. }else{
  111. player_togglePause();
  112. }
  113. }else{
  114. jQuery(this).attr('src',DIR_PLUGIN_PLAYER + 'skins/blogo/play.png');
  115. player_togglePause();
  116. }
  117. });
  118. // chopper les coordonnees du clic dans la barre de progression
  119. jQuery("#scrollbar").click(function(e){
  120. var x = Math.round((e.pageX - this.offsetLeft) / jQuery(this).width() * 100);
  121. if(live_track !== 'stop'){
  122. var mySound = soundManager.getSoundById('son_' + track_index);
  123. var newposition = Math.round(mySound.durationEstimate * x / 100) ;
  124. soundManager.setPosition('son_' + track_index , newposition) ;
  125. }
  126. // pareil pour les videos
  127. if(isVideoPlaying){
  128. var position = Math.round(myListener.duration * x / 100);
  129. getFlashObject().SetVariable("method:setPosition", position);
  130. }
  131. });
  132. jQuery("#now_playing").change(function(){
  133. scroller_init();
  134. });
  135. // si option choisie, presser la barre espace arrete le lecteur
  136. if (key_espace_stop) {
  137. jQuery(document).keypress(function(e)
  138. {
  139. key = (e.charCode) ? e.charCode : e.keyCode;
  140. if(
  141. (key == 32) // espace
  142. || (key == 27) // esc
  143. ) {
  144. if(isPlaying) {
  145. player_togglePause();
  146. }
  147. if (isVideoPlaying) {
  148. // toto: faire la meme chose pour la video ?
  149. }
  150. }
  151. });
  152. }
  153. }
  154. // .play() plugin jquery
  155. function player_play(i){
  156. player_stop();
  157. jQuery("#bouton_play").attr('src',DIR_PLUGIN_PLAYER + 'skins/blogo/pause.png');
  158. track_index = i ;
  159. live_track = i ;
  160. //jQuery("span.play_:eq("+i+")").html("stop").addClass("play_on");
  161. jQuery("span.play_:eq("+i+")").html("<img src='" + image_pause + "'/>").addClass("play_on");
  162. // i c pas forcemment bon si t'as un player avant le lien, il faut retrancher le nb d'item de la playlist du lecteur
  163. // (ne pas mettre enclosure aux deux ?)
  164. // limiter une playliste a son parent plutot qu'a la page ?
  165. jQuery(".play_:eq("+i+")").addClass("play_on");
  166. if(soundManager.url != 'undefined'){
  167. player_creer_son(i);
  168. //jQuery("span#now_playing").html(i+"("+mp3Array[i]+")"+track_index);
  169. //jQuery("span#now_playing").append("son_"+i.id3.artist);
  170. file1 = mp3Titles[track_index];
  171. file1 = file1.replace(/(%20)/g,' ');
  172. file1 = file1.substr(0,90);
  173. file1 = file1.replace(/(.mp3)/g,' ');
  174. file1 = file1.replace(/(_|-)/g,' ');
  175. //jQuery("img["+seljQ+"alt='play']").attr()
  176. var taille = file1.length;
  177. //$large_s = taille * 7; // pas bon. Laisser le navigateur decider
  178. $large_s = 'auto';
  179. jQuery("#now_playing").width($large_s);
  180. jQuery("#scroller").width($large_s);
  181. jQuery("#now_playing").html(file1) ;
  182. var taille = jQuery("#scroller").width();
  183. var min_taille = jQuery("#scroller_container").width();
  184. // adapter le defilement a la taille du texte
  185. jQuery.extend({scroller: {
  186. interval: 0,
  187. refresh: 300, // Refresh Time in ms
  188. direction: "left", // down,right,left,up
  189. speed: 2,
  190. id: "#scroller",
  191. cont_id: "#scroller_container",
  192. height: 30,
  193. width: taille,
  194. min_height: 15,
  195. min_width: min_taille
  196. }});
  197. jQuery("#scroller").css("left", min_taille-taille) ;
  198. soundManager.play('son_'+i,{volume:100}) ;
  199. isPlaying = true ;
  200. //lecteur_debug();
  201. }else{
  202. // preparer un plan B si flash < 8
  203. var playa='';
  204. playa = '<div id="musicplayer" style="">' +
  205. '</div>';
  206. jQuery('body').append(playa);
  207. jQuery('div#musicplayer').css({position:"fixed",top:"10px", right:"10px",width:"0",height:"0"});
  208. //Ajouter le musicplayer de secours
  209. playlist='';
  210. deb=0;
  211. for(j=i; j < mp3Array.length ; j++) {
  212. if(deb > 0){
  213. // Modification du code original. Voir ci-dessous.
  214. playlist = playlist + '|' + mp3Array[j];
  215. // Fin modification
  216. }else{
  217. playlist = mp3Array[j];
  218. deb=1;
  219. }
  220. }
  221. jQuery("#musicplayer").html('<object '+
  222. 'type="application/x-shockwave-flash" '+
  223. 'data="'+musicplayerurl+'" '+
  224. 'width="1" height="1" align="middle">'+
  225. '<param name="FlashVars" value="song_url='+playlist+'" />'+
  226. '<param name="wmode" value="transparent" />'+
  227. '<param name="movie" value="'+musicplayerurl+'" />'+
  228. '</object>');
  229. // Fin modification
  230. }
  231. }
  232. function player_creer_son(i){
  233. soundManager.createSound({
  234. id:'son_'+i,url:mp3Array[i],
  235. onfinish:function(){
  236. /*console.log(this.sID+' finished playing'),*/
  237. player_play(i+1)
  238. },
  239. onid3:function(){
  240. /*console.log(this.id3['songname'])*/
  241. },
  242. onload:function(){
  243. /*console.log(this.sID+' finished loading')*/
  244. },
  245. whileloading:function(){
  246. /*console.log('sound '+this.sID+' loading, '+this.bytesLoaded+' of '+this.bytesTotal);*/
  247. var timer = this.bytesLoaded / this.bytesTotal * 100 ;
  248. var minutes = Math.floor(this.durationEstimate / 1000 / 60) ;
  249. var secondes = Math.floor((this.durationEstimate - minutes*1000*60) /1000);
  250. jQuery(".duration").html(minutes + "'" + secondes +"''");
  251. jQuery("#loading").css({width:Math.round(timer) +"%"});
  252. }, // callback function for "download progress update" (X of Y bytes received)
  253. onplay:function(){
  254. jQuery("#loading").css("cursor","hand");
  255. var minutes = Math.floor(this.durationEstimate / 1000 / 60) ;
  256. var secondes = Math.floor((this.durationEstimate - minutes*1000*60) /1000);
  257. jQuery(".duration").html(minutes + "'" + secondes +"''");
  258. },// callback for "play" start
  259. whileplaying:function(){
  260. var minutes = Math.floor(this.position / 1000 / 60) ;
  261. var secondes = Math.floor((this.position - minutes*1000*60) /1000);
  262. var timer2 = this.position / this.durationEstimate * 100 ;
  263. jQuery("#position").css({width:Math.round(timer2) +"%"});
  264. jQuery(".position").html(minutes + "'" + secondes +"''");
  265. },// callback during play (position update)
  266. //'onstop':unLoad(this.sID), // callback for "user stop"
  267. //'onbeforefinish': null, // callback for "before sound finished playing (at [time])"
  268. //'onbeforefinishtime': 5000, // offset (milliseconds) before end of sound to trigger beforefinish..
  269. //'onbeforefinishcomplete':null, // function to call when said sound finishes playing
  270. //'onjustbeforefinish':null, // callback for [n] msec before end of current sound
  271. //'onjustbeforefinishtime':200, // [n] - if not using, set to 0 (or null handler) and event will not fire.
  272. //'multiShot': true, // let sounds "restart" or layer on top of each other when played multiple times..
  273. //'pan': 0, // "pan" settings, left-to-right, -100 to 100
  274. 'volume': 100
  275. });
  276. }
  277. function player_stop(){
  278. //reinit d'un autre play
  279. isPlaying = false ;
  280. //jQuery("span.play_on").html('play');
  281. jQuery("span.play_on").html('<img src="' + image_play + '"/>');
  282. jQuery("span.play_on").removeClass("play_on");
  283. live_track = 'stop' ;
  284. jQuery(".playliste li.play_on").removeClass("play_on");
  285. reset_boutons();
  286. soundManager.destroySound("son_" + track_index);
  287. soundManager.stopAll();
  288. //stop le musicplayer en flash < 8
  289. jQuery("#musicplayer").html('');
  290. jQuery("#now_playing").html('');
  291. }
  292. function unLoad(i){
  293. soundManager.unload(i);
  294. /*console.log(i+' unload hop');*/
  295. }
  296. function player_next(){
  297. unLoad("son_" + track_index);
  298. track_index++;
  299. //file1=(mp3Array[track_index].split("/"))[(mp3Array[track_index].split("/")).length-1];
  300. //jQuery("#now_playing").html(file1) ;
  301. player_play(track_index);
  302. }
  303. function player_prev(){
  304. unLoad("son_" + track_index);
  305. track_index--;
  306. //file1=(mp3Array[track_index].split("/"))[(mp3Array[track_index].split("/")).length-1];
  307. //jQuery("#now_playing").html(file1) ;
  308. player_play(track_index);
  309. }
  310. function player_togglePause(){
  311. soundManager.togglePause('son_'+live_track) ;
  312. //console.log(isPlaying);
  313. if(isPlaying == true){
  314. isPlaying = false ;
  315. }else{
  316. isPlaying = true ;
  317. }
  318. }
  319. function reset_boutons(){
  320. jQuery("#bouton_play").attr('src',DIR_PLUGIN_PLAYER + 'skins/blogo/play.png');
  321. jQuery(".position").html("0'00''");
  322. jQuery("#position,#loading").width(0);
  323. }
  324. function Player_init(url_player) {
  325. soundManager.onload = function() {
  326. // soundManager is initialised, ready to use. Create a sound for this demo page.
  327. soundManager.createSound('aDrumSound',url_player);
  328. }
  329. }
  330. // Nouvelle methode pour les tableaux
  331. // Retourne la premiere occurence correspondant, sinon false
  332. Array.prototype.contains = function (ele) {
  333. for (var i = 0; i < this.length; i++) {
  334. if (this[i] == ele) {
  335. return true;
  336. }
  337. }
  338. return false;
  339. };
  340. // lecteur video
  341. // doc : http://flv-player.net/players/js/documentation/
  342. function video_play(i){
  343. track_index = i ;
  344. live_video = i ;
  345. if (!videoPause) {
  346. video_stop();
  347. getFlashObject().SetVariable("method:setUrl", flvArray[i]);
  348. }
  349. getFlashObject().SetVariable("method:play", "");
  350. videoPause = false ;
  351. jQuery(".playliste li:eq("+i+")").addClass("play_on");
  352. }
  353. function video_pause(){
  354. if(videoPause){ videoPause = false } else { videoPause = true }
  355. getFlashObject().SetVariable("method:pause", "");
  356. }
  357. function video_next(){
  358. track_index++;
  359. video_play(track_index);
  360. }
  361. function video_prev(){
  362. track_index--;
  363. video_play(track_index);
  364. }
  365. function video_stop(){
  366. jQuery(".playliste li.play_on").removeClass("play_on");
  367. getFlashObject().SetVariable("method:stop", "");
  368. getFlashObject().SetVariable("method:setUrl", videoNullUrl);
  369. getFlashObject().SetVariable("method:play", "");
  370. getFlashObject().SetVariable("method:stop", "");
  371. getFlashObject().SetVariable("method:setPosition", 0);
  372. }
  373. function video_setVolume(){
  374. var volume = document.getElementById("inputVolume").value;
  375. getFlashObject().SetVariable("method:setVolume", volume);
  376. }
  377. function lecteur_debug(){
  378. var content = jQuery("#debug").html() ;
  379. jQuery("#debug").html(content + "<br />live_track = " +live_track ) ;
  380. };