Skip to content

Instantly share code, notes, and snippets.

@lustremedia
Forked from whitperson/gist:4277811
Created February 7, 2014 11:07
Show Gist options
  • Save lustremedia/8860815 to your computer and use it in GitHub Desktop.
Save lustremedia/8860815 to your computer and use it in GitHub Desktop.
var vol = 20;
var t = 0;
function playSample(id) {
$("#player").stop();
vol = 20;
stopSample();
$("#player").setFile("yourfile.mp3");
fadeIn();
$("#player").play();
}
function stopSample(id, fadeout) {
clearTimeout(t);
//Set fadeout = true in the function call: <a href="#" onClick="stopSample(23, true);">Stop</a>
if(fadeout == true) {fadeOut();}
}
$("#player").jPlayer({
swfPath: "swfpath";
});
$("#player").onSoundComplete(function() {
stopSample();
});
function fadeIn() {
if(vol < 150) {
$("#player").volume(vol);
t = setTimeout("fadeIn()", 200);
vol = vol + 10;
} else {
clearTimeout(t);
vol = 150;
}
}
function fadeOut() {
if(vol > 0) {
$("#player").volume(vol);
t = setTimeout("fadeOut()", 200);
vol = vol - 10;
} else {
clearTimeout(t);
$("#player").stop();
vol = 20;
}
}
$("#player").onProgressChange(function (l,pr,pa,pt,t) {
if(pa > 90 && pa < 92) {
stopSample(0, true);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment