Skip to content

Instantly share code, notes, and snippets.

@jpbyrne
Created April 11, 2013 19:13
Show Gist options
  • Save jpbyrne/5366336 to your computer and use it in GitHub Desktop.
Save jpbyrne/5366336 to your computer and use it in GitHub Desktop.
$(document).ready(function() {
var theMP3;
var currentSong = 0;
var tracks = ["1","2","3","4","5"];
var id3s=[];
$jScroller.add("#scroller_container","#scroller","left",2);
$jScroller.cache.init = true; // Turn off default Event
$jScroller.config.refresh = 100;
$( "#progressbar" ).progressbar({
value: 0
});
function updateArtist(){
$jScroller.stop();
if(id3s[currentSong] !=undefined){
$("#scroller p").text(id3s[currentSong]["theArtist"] + " : " + id3s[currentSong]["theTitle"] );
}
$jScroller.reset();
$jScroller.add("#scroller_container","#scroller","left",2);
var t=setTimeout(startScroller,2000);
}
function startScroller(){
$jScroller.start();
}
soundManager.url = 'swf';
soundManager.flashVersion = 8;
soundManager.onready(function() {
function playSound(){
if(currentSong>=tracks.length){
currentSong=0;
}
if(currentSong<0){
currentSong = tracks.length-1;
}
theMP3= soundManager.createSound({
id:'sound'+currentSong,
url:"sounds/"+tracks[currentSong]+".mp3",
whileplaying:function(){
duration = this.duration;
pos = this.position;
songPosition = (pos/duration)*100;
$( "#progressbar" ).progressbar( "option", "value", songPosition);
var time = pos/1000;
var min = Math.floor(time/60);
var minDisplay = (min<10) ? "0"+min : min;
var sec = Math.floor(time%60);
var secDisplay = (sec<10) ? "0"+sec : sec;
var amountPlayed = minDisplay+":"+secDisplay;
var timeduration = duration/1000;
var minduration = Math.floor(timeduration/60);
var minDisplay = (minduration<10) ? "0"+minduration : minduration;
var secduration = Math.floor(timeduration%60);
var secDisplay = (secduration<10) ? "0"+secduration : secduration;
var totalDuration = minDisplay+":"+secDisplay;
$("#time").text(amountPlayed +" / "+totalDuration);
},
onid3:function(){
artist = this.id3["TPE1"];
title = this.id3["TIT2"];
id3s.push({theArtist:artist,theTitle:title});
updateArtist();
},
onfinish:function() {
currentSong++;
playSound();
updateArtist();
}
});
theMP3.play();
};
$("#play_btn").click(function(){
var thebutton = $(this);
if(thebutton.attr("src")=="images/play_button.png"){
$("#pause_btn").attr("src","images/pause_button.png");
$("#stop_btn").attr("src","images/stop_button.png");
thebutton.attr("src","images/play_selected.png");
playSound();
$jScroller.start();
}
}).mouseover(function(){
$(this).css("cursor","pointer");
});
$("#stop_btn").click(function(){
$jScroller.stop();
$("#pause_btn").attr("src","images/pause_button.png");
$("#play_btn").attr("src","images/play_button.png");
$(this).attr("src","images/stop_selected.png");
theMP3.stop();
}).mouseover(function(){
$(this).css("cursor","pointer");
});
$("#pause_btn").click(function(){
$jScroller.stop();
$("#stop_btn").attr("src","images/stop_button.png");
$("#play_btn").attr("src","images/play_button.png");
$(this).attr("src","images/pause_selected.png");
theMP3.pause();
}).mouseover(function(){
$(this).css("cursor","pointer");
});
$("#fwd_btn").click(function(){
if(theMP3 !=undefined){
theMP3.stop();
currentSong++;
playSound();
updateArtist();
}
}).mouseover(function(){
$(this).css("cursor","pointer");
});
$("#back_btn").click(function(){
if(theMP3 != undefined){
theMP3.stop();
currentSong--;
playSound();
updateArtist();
}
}).mouseover(function(){
$(this).css("cursor","pointer");
});
$("#volumebar").mousemove(function(e){
var parentOffset = $(this).parent().offset();
var relX = Math.floor(e.pageX - parentOffset.left);
var vol = Math.ceil( (relX-7)/10)-4;
console.log(vol);
if(vol >=1 && vol <=10){
$(this).attr("src","images/vb"+vol+".png");
if(theMP3 != undefined){
theMP3.setVolume(vol*10)
}
}
}).mouseover(function(){
$(this).css("cursor","pointer");
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment