5 init_player_listener();
9 // -----------------------------------------------------------------
13 var current_document = false;
14 var autoplay_next = false;
16 function init_players(target){
17 $(target == "*" ? "audio" : target + " audio").each
19 { var audio_elt = $(this).get(0);
21 var id_document = $(this).attr("id").substring(6);
23 if((k = id_document.indexOf("_")) != -1) id_source = id_document.substring(0, k);
25 $(this).find("source").each(
27 if(audio_elt.canPlayType($(this).attr("type"))) CAN_PLAY = true;
31 audio_elt.addEventListener("ended", track_ended, false);
32 $("#player_" + id_document + " .play").click(function() { play(id_document); return false; });
33 $("#player_" + id_document + " .play").css("display", "inline");
34 $("#player_" + id_document + " .pause").click(function() { pause(); return false; });
35 $("#player_" + id_document + " .pause").css("display", "none");
36 $("#player_" + id_document + " .stop").click(function() { stop(); return false; });
37 $("#player_" + id_document + " .stop").css("display", "none");
38 $("#document_" + id_document + " .no_player").remove();
41 if(!CAN_PLAY) $("#player_" + id_document).remove();
44 $(target == "*" ? ".track" : target + " .track").each(
46 if($(this).find(".player").size()){
47 var id_source = $(this).attr("id").substring(6);
48 $(this).find(".player_progress").first().click(
50 if((progress_width = $(this).width()) != 0){
51 play_source_from(id_source, (100 * (e.pageX - this.offsetLeft)) / progress_width);
56 else $(this).find(".player_progress").first().css("cursor", "default");
61 function init_player_listener(){
62 setInterval("player_listener_update()", 300);
65 function player_listener_update(){
67 (current_document != false)
68 && (source_id = get_current_source_id())
69 && (current_audio = $("#audio_" + current_document).get(0))
70 && ($("#track_" + source_id + " .player_progress").size())
72 $("#track_" + source_id + " .player_progress .position").not(
73 "#track_" + source_id + " .pistes .player_progress .position").not(
74 "#track_" + source_id + " .derivation .player_progress .position").css(
76 Math.round((100 * current_audio.currentTime) / current_audio.duration) + "%"
81 function get_current_source_id(){
82 if(current_document != false){
83 if($("#document_" + current_document).size()){
84 var source_document_id = $("#document_" + current_document).attr("id").substring(9);
85 if((k = source_document_id.indexOf("_")) != -1){
86 return source_document_id.substring(0, k);
94 autoplay_next = play_first_source();
97 function play_first_source(){
99 $(".track").not(".pistes .track").not(".derivation .track").each(
102 $(this).find(".documents li").not(".pistes .documents li").not(".derivation .documents li").each(
105 var source_document_id = $(this).attr("id").substring(9);
106 if(source_document_id.length > 0){
107 if($("#player_" + source_document_id).size()){
109 play(source_document_id);
121 function play_next_source(){
123 if(current_document != false){
124 if($("#document_" + current_document).size()){
125 var current_source_document_id = $("#document_" + current_document).attr("id");
126 var current_source_id = get_current_source_id();
127 if(current_source_id != false){
128 var CURRENT_FOUND = false;
129 $(".track").not(".pistes .track").not(".derivation .track").each(
133 $(this).find(".documents li").not(".pistes .documents li").not(".derivation .documents li").each(
136 var source_document_id = $(this).attr("id").substring(9);
137 if(source_document_id.length > 0){
138 if($("#player_" + source_document_id).size()){
140 play(source_document_id);
148 if(current_source_id == $(this).attr("id").substring("6")){
149 CURRENT_FOUND = true;
161 function play(id_document){
162 if(current_document == id_document){
163 if($("#audio_" + current_document).get(0).paused){
164 gui_state("playing");
165 $("#audio_" + current_document).get(0).play();
169 if(current_document != false){
170 var audio_elt = $("#audio_" + current_document).get(0);
172 audio_elt.currentTime = 0;
175 current_document = id_document;
180 function play_source_from(id_source, position){
182 (current_document != false)
183 && (current_source_id = get_current_source_id())
184 && (id_source == current_source_id)
191 $("#track_" + id_source + " .documents li").each(
194 var source_document_id = $(this).attr("id").substring(9);
195 if(source_document_id.length > 0){
196 if($("#player_" + source_document_id).size()){
198 current_document = source_document_id;
208 function _play(position){
209 if(current_document != false){
210 var audio_elt = $("#audio_" + current_document).get(0);
211 audio_elt.preload = "auto";
212 audio_elt.addEventListener("loadeddata", track_loadeddata, false);
213 audio_elt.addEventListener("canplaythrough", track_canplaythrough, false);
214 audio_elt.addEventListener("playing", track_playing, false);
215 gui_state("loading");
216 audio_elt.position = position;
221 function track_loadeddata(event){
222 var audio_elt = event.target;
223 audio_elt.removeEventListener("loadeddata", track_loadeddata, false);
224 if(current_document != false){
225 audio_elt.currentTime = audio_elt.position ? (audio_elt.position * audio_elt.duration) / 100 : 0;
229 function track_canplaythrough(event){
230 var audio_elt = event.target;
231 audio_elt.removeEventListener("canplaythrough", track_canplaythrough, false);
235 function track_playing(event){
236 var audio_elt = event.target;
237 audio_elt.removeEventListener("playing", track_playing, false);
238 gui_state("playing");
242 if(current_document != false){
243 var audio_elt = $("#audio_" + current_document).get(0);
250 if(current_document != false){
251 var audio_elt = $("#audio_" + current_document).get(0);
253 audio_elt.currentTime = 0;
255 current_document = false;
257 autoplay_next = false;
260 function track_ended(){
262 var current_audio = $("#audio_" + current_document).get(0);
263 current_audio.pause();
264 if(current_audio.currentTime) current_audio.currentTime = 0;
265 if(autoplay_next) autoplay_next = play_next_source();
268 function gui_state(state){
270 if(current_document != false){
271 var source_id = get_current_source_id();
272 $("#track_" + source_id).removeClass("loading_player");
273 if(state == "playing"){
274 $("#player_" + current_document).find(".play").css("display", "none");
275 $("#player_" + current_document).find(".pause").css("display", "inline");
276 $("#player_" + current_document).find(".stop").css("display", "inline");
277 // $("#track_" + source_id).removeClass("track");
278 $("#track_" + source_id).addClass("playing_track");
280 else if(state == "paused"){
281 $("#player_" + current_document).find(".play").get(0).style.display = "inline";
282 $("#player_" + current_document).find(".pause").get(0).style.display = "none";
283 $("#player_" + current_document).find(".stop").get(0).style.display = "inline";
284 // $("#track_" + source_id).removeClass("track");
285 $("#track_" + source_id).addClass("playing_track");
287 else if(state == "stoped"){
288 $("#player_" + current_document).find(".play").get(0).style.display = "inline";
289 $("#player_" + current_document).find(".pause").get(0).style.display = "none";
290 $("#player_" + current_document).find(".stop").get(0).style.display = "none";
291 $("#track_" + source_id).removeClass("playing_track");
292 // $("#track_" + source_id).addClass("track");
293 $("#track_" + source_id + " .player_progress .position").not(
294 "#track_" + source_id + " .pistes .player_progress .position").not(
295 "#track_" + source_id + " .derivation .player_progress .position").css("width", "0%");
297 else if(state == "loading"){
298 $("#track_" + source_id).addClass("loading_player");
304 if((current_document != false) && $("#player_" + current_document).size()){
305 $("#player_" + current_document).find(".play").get(0).blur();
306 $("#player_" + current_document).find(".pause").get(0).blur();
307 $("#player_" + current_document).find(".stop").get(0).blur();
311 // -----------------------------------------------------------------
316 var show_xml_links = {};
318 function show_xml(id){
319 alert(xml_contents[id]);
322 function init_show_xml_links(){
323 for(var i in show_xml_links){
324 $("#show_xml_" + i).colorbox();
329 function set_show_xml_links(i){
330 if(loaded) $("#show_xml_" + i).colorbox();
331 else show_xml_links[i] = true;
334 // -----------------------------------------------------------------
335 // sources / derivations
338 function toggle_source_list(id_block){
339 var content = $("#source_list_" + id_block + " .pistes").html();
340 if(content.length > 0){
341 $("#source_list_" + id_block).slideUp(200);
342 $("#source_list_" + id_block + " .pistes").empty();
343 $("#toggle_sources_list_" + id_block + ".block_list_toggle").html("[+]");
346 $("#source_list_" + id_block).slideDown(200);
347 $("#toggle_sources_list_" + id_block + ".block_list_toggle").html("[-]");
348 $("#source_list_" + id_block + " .pistes").html("<div class=\"loading\"><span>en chargement...</span></div>");
350 url: mw_site_url + "index.php?e=content/sources/sources&id=" + id_block,
352 success: function(content){
353 $("#source_list_" + id_block + " .pistes").html(content);
354 init_players("#source_list_" + id_block + " .pistes");
360 function toggle_derivation_list(id_block){
361 var content = $("#derivation_list_" + id_block + " .derivation").html();
362 if(content.length > 0){
363 $("#derivation_list_" + id_block).slideUp(200);
364 $("#derivation_list_" + id_block + " .derivation").empty();
365 $("#toggle_derivation_list_" + id_block + ".block_list_toggle").html("[+]");
368 $("#derivation_list_" + id_block).slideDown(200);
369 $("#toggle_derivation_list_" + id_block + ".block_list_toggle").html("[-]");
370 $("#derivation_list_" + id_block + " .derivation").html("<div class=\"loading\"><span>en chargement...</span></div>");
372 url: mw_site_url + "index.php?e=content/sources/derivations&id=" + id_block,
374 success: function(content){
375 $("#derivation_list_" + id_block + " .derivation").html(content);
376 init_players("#derivation_list_" + id_block + " .derivation");