Commit da358ca3 authored by Mike Sheldon's avatar Mike Sheldon

Move all javascript into one place to remove need for links to s.libre.fm

parent 05ce6102
This diff is collapsed.
var scrobbled,now_playing;var artist,album,track,session_key,radio_key;var playlist=[],current_song=0;var player_ready=false;var playable_songs=false;var streaming=false;function playerInit(c,a,d){var b=document.getElementById("audio");if(!c){streaming=true}session_key=a;radio_key=d;if(typeof b.duration=="undefined"){if(streaming){b.replaceWith("<p>Sorry, you need a browser capable of using the HTML 5 &lt;audio&gt; element to enjoy the streaming service via the Javascript player.</p>")}return}$("#fallbackembed").replaceWith("");if(streaming){getRadioPlaylist()}else{playlist=c;playerReady()}}function playerReady(){var a=document.getElementById("audio");populatePlaylist();if(!playable_songs){return}loadSong(0);a.pause();a.addEventListener("ended",songEnded,false);updateProgress();$("#play").fadeTo("normal",1);$("#progressbar").progressbar({value:0});$("#player > #interface").show();player_ready=true}function play(){var a=document.getElementById("audio");a.play();if(!now_playing){nowPlaying()}$("#play").fadeTo("normal",0.5);$("#pause").fadeTo("normal",1);$("#seekforward").fadeTo("normal",1);$("#seekback").fadeTo("normal",1)}function pause(){var a=document.getElementById("audio");a.pause();$("#play").fadeTo("normal",1);$("#pause").fadeTo("normal",0.5);$("#seekforward").fadeTo("normal",0.5);$("#seekback").fadeTo("normal",0.5)}function seekBack(){var a=document.getElementById("audio");a.currentTime=a.currentTime-10}function seekForward(){var a=document.getElementById("audio");a.currentTime=a.currentTime+10}function updateProgress(){var a=document.getElementById("audio");if(a.duration>0){$("#progressbar").progressbar("option","value",(a.currentTime/a.duration)*100)}if(!scrobbled&&a.currentTime>a.duration/2){scrobble()}$("#currenttime").text(friendlyTime(a.currentTime));$("#duration").text(friendlyTime(a.duration));setTimeout("updateProgress()",900)}function songEnded(){var a=document.getElementById("audio");if(current_song==playlist.length-1){pause()}else{loadSong(current_song+1);play()}}function populatePlaylist(){var b,a;$("#playlist > #songs").text("");for(b=0;b<playlist.length;b++){a=playlist[b]["url"];if(a==""){playlist.pop(song)}else{playable_songs=true}$("#playlist > #songs").append("<li id='song-"+b+"'><a href='#' onclick='playSong("+b+")'>"+playlist[b]["artist"]+" - "+playlist[b]["track"]+"</li>")}$("#song-"+current_song).css({fontWeight:"bold"})}function togglePlaylist(){$("#playlist").toggle(1000);$("#showplaylist").toggle();$("#hideplaylist").toggle()}function scrobble(){var a;scrobbled=true;if(!session_key){return}a=Math.round(new Date().getTime()/1000);$.post("/scrobble-proxy.php?method=scrobble",{"a[0]":artist,"b[0]":album,"t[0]":track,"i[0]":a,s:session_key},function(b){if(b.substring(0,2)=="OK"){$("#scrobbled").fadeIn(5000,function(){$("#scrobbled").fadeOut(5000)})}else{$("#scrobbled").text(b);$("#scrobbled").fadeIn(1000)}},"text")}function nowPlaying(){var b;var a=document.getElementById("audio");now_playing=true;if(!session_key){return}b=Math.round(new Date().getTime()/1000);$.post("/scrobble-proxy.php?method=nowplaying",{a:artist,b:album,t:track,l:a.duration,s:session_key},function(c){},"text")}function playSong(b){var a=document.getElementById("audio");loadSong(b);play()}function loadSong(c){var a=playlist[c]["url"];var b=document.getElementById("audio");artist=playlist[c]["artist"];album=playlist[c]["album"];track=playlist[c]["track"];$("#song-"+current_song).css({fontWeight:"normal"});$("#song-"+c).css({fontWeight:"bold"});current_song=c;scrobbled=false;now_playing=false;b.src=a;b.load();if(streaming&&current_song>playlist.length-3){getRadioPlaylist()}if(current_song>0){$("#skipback").fadeTo("normal",1)}else{$("#skipback").fadeTo("normal",0.5)}if(current_song<playlist.length-1){$("#skipforward").fadeTo("normal",1)}else{$("#skipforward").fadeTo("normal",0.5)}$("#trackinfo > #artistname").text(artist);$("#trackinfo > #trackname").text(track)}function getRadioPlaylist(){var d,a,b,f,c,e;$.get("/radio/xspf.php",{sk:radio_key,desktop:0},function(h){parser=new DOMParser();xmlDoc=parser.parseFromString(h,"text/xml");d=xmlDoc.getElementsByTagName("track");for(e=0;e<d.length;e++){try{a=d[e].getElementsByTagName("creator")[0].childNodes[0].nodeValue;f=d[e].getElementsByTagName("title")[0].childNodes[0].nodeValue;b=d[e].getElementsByTagName("album")[0].childNodes[0].nodeValue;c=d[e].getElementsByTagName("location")[0].childNodes[0].nodeValue;playlist.push({artist:a,album:b,track:f,url:c})}catch(g){}}if(!player_ready){playerReady()}else{populatePlaylist();$("#skipforward").fadeTo("normal",1)}},"text")}function skipBack(){playSong(current_song-1)}function skipForward(){playSong(current_song+1)}function friendlyTime(a){mins=Math.floor(a/60);sec=String(Math.floor(a%60));if(sec.length==1){sec="0"+sec}return mins+":"+sec};
This diff is collapsed.
......@@ -85,7 +85,6 @@ function playerReady() {
$("#ban").fadeTo("normal", 1);
$("#love").fadeTo("normal", 1);
$("#open_tag").fadeTo("normal", 1);
$("#close_tag").fadeTo("normal", 1);
$("#progressbar").progressbar({ value: 0 });
$("#player > #interface").show();
$("#tags").placeholdr({placeholderText: example_tags});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment