#HTTP_HEADER{Content-Type: text/javascript} #CACHE{24*3600,cache-client} $(document).ready(function(){ soundManager.setup({ url: '[(#CHEMIN{swf/soundmanager2.swf}|url_absolue|dirname)/]', flashVersion: 9, // optional: shiny features (default = 8) useFlashBlock: false, // optionally, enable when you're ready to dive in debugMode: false, /** * read up on HTML5 audio support, if you're feeling adventurous. * iPad/iPhone and devices without flash installed will always attempt to use it. */ onready: function() { // Ready to use; soundManager.createSound() etc. can now be called. lastSound = soundManager.createSound({id:'Hello',url:''}); sound_manager_init(); onAjaxLoad(sound_manager_init); } }); }); function sound_manager_init(){ // indexer les liens mp3 et ogg $("a[rel='enclosure'][href*='.mp3'],a[rel='enclosure'][href*='.ogg']").each(function(i){ $(this).attr('data-soundId',i); $(this).on("click",function(e){ return false ; }); }); // animation des boutons $(".play") .html("play") .unbind('click') .click( function(e) { e.preventDefault(); $(".playing").removeClass("playing"); if ($(this).text() === "play") { $(this).html("pause") .attr("title", $(this).attr("data-pause")); } else { $(this).html("play") .attr("title", $(this).attr("data-lecture")); } var media_index = $(this).index(); var parent_track = $(this).parents(".audio").eq(0) ; var lienMp3 = parent_track.addClass("playing").find("a[rel='enclosure']") ; var media_url = lienMp3.attr('href'); var media_id = "media_" + lienMp3.attr('data-soundId'); // ajouter une class pour cibler les barres de progression de ce son parent_track.addClass(media_id); jouer_son(media_id, media_url); }); $(".stop").click(function() { media_en_cours = $(".playing").attr("class").match('media_.*')[0] ; soundManager.stopAll(); soundManager.destroySound(media_en_cours); $("button.play").html("play") .attr("title", $("button.play").attr("data-lecture")); $(".position").width(0); }); } function jouer_son(media_id, media_url){ var soundURL = media_url; var soundId = media_id ; var thisSound = soundManager.getSoundById(soundId); // des infos sur le prochain son var next = parseInt(media_id.match('media_(.*)')[1],10) + 1 ; var next_sound_id = "media_" + next ; var next_sound_url = $("a[data-soundId='"+ next +"'][href$=mp3]").attr('href'); var next_sound_parent = $("a[data-soundId='"+ next +"'][href$=mp3]").parents('.audio'); if (thisSound) { // already exists if (thisSound == lastSound) { // and was playing (or paused) thisSound.togglePause(); } else { // different sound thisSound.togglePause(); // start playing current if (lastSound) { soundManager.stop(lastSound.sID); soundManager.unload(lastSound.sID); lastSound = thisSound ; } } } else { // create sound thisSound = soundManager.createSound({ id:soundId, url:soundURL, multiShot: false, autoPlay: false, autoLoad: true, onplay:function(){ }, whileloading:function(){ var timer = this.bytesLoaded / this.bytesTotal * 100 ; var minutes = Math.floor(this.durationEstimate / 1000 / 60) ; var secondes = Math.floor((this.durationEstimate - minutes*1000*60) /1000); if(secondes < 10) secondes = "0" + secondes ; if(minutes < 10) minutes = "0" + minutes ; $("." + this.sID +" .duration").html("/ " + minutes + ":" + secondes); $("." + this.sID +" .loading").css({width:Math.round(timer) +"%"}); }, whileplaying:function(){ var minutes = Math.floor(this.position / 1000 / 60) ; var secondes = Math.floor((this.position - minutes*1000*60) /1000); if(secondes < 10) secondes = "0" + secondes ; if(minutes < 10) minutes = "0" + minutes ; var timer = this.position / this.durationEstimate * 100 ; $("." + this.sID +" .position").css({width:timer +"%"}); $("." + this.sID +" .time").html(minutes + ":" + secondes); }, onfinish:function(){ $("." + this.sID).find(".stop").trigger("click"); if(next_sound_id && next_sound_url) next_sound_parent.find(".play").trigger("click"); } }); // stop last sound if (lastSound) { soundManager.stop(lastSound.sID); soundManager.unload(lastSound.sID); } lastSound = thisSound ; thisSound.play(); // deplacer le son $("." + media_id + ".progress_bar, ." + media_id + " .progress_bar").click(function(e){ // deplacer proportionellement le son var duree = thisSound.durationEstimate; var offset = $(this).offset(); var x = (e.pageX - offset.left) / $(this).width() ; var temps = duree * x; // ne pas agir sur un bouton play ou stop bp = $(this).find(".play") ; bs = $(this).find(".stop") ; if( e.pageX > bp.offset().left && e.pageX < bp.offset().left + bp.width() || e.pageX > bs.offset().left && e.pageX < bs.offset().left + bs.width() ){ // console.log("occupé, ps :", thisSound.playState); }else{ $(this).find(".position").css({width:x * 100 +"%"}); thisSound.setPosition(temps); } }); } }