This tiny script will raise the quality of the music preview's sound.
Features
1. Fade in when music start
2. Fade out when the music ends
3. Fade in and out when the music changes
4. Fade out when turning off with the button
Fixed all the bugs!
(except the one that negate the fadein feature when MP3file loads slowly)
The source code got longer because of the bug-fixing
You can activate this script by following the next steps. I test in Chrome, Safari. (It just work in webkit rendering engine?!)
1. press F12 (Chrome, IE) Ctrl+Shift+I (Opera) Ctrl+Alt+C (Safari)
2. Click Console(JavaScript Console)
3. Paste the minimized code
4. Play the music.
minimum
For Developers (Debugging 'console.log')
Normal
Features
1. Fade in when music start
2. Fade out when the music ends
3. Fade in and out when the music changes
4. Fade out when turning off with the button
Fixed all the bugs!
(except the one that negate the fadein feature when MP3file loads slowly)
The source code got longer because of the bug-fixing
You can activate this script by following the next steps. I test in Chrome, Safari. (It just work in webkit rendering engine?!)
1. press F12 (Chrome, IE) Ctrl+Shift+I (Opera) Ctrl+Alt+C (Safari)
2. Click Console(JavaScript Console)
3. Paste the minimized code
4. Play the music.
minimum
SPOILER
var muout,muin,mx,fis,fos,fo;function sleep(numberMillis){var now=new Date();var exitTime=now.getTime()+numberMillis;while(true){now=new Date();if(now.getTime()>exitTime){return false;}}}function fadeout(vol,ts){muout=vol;fos=ts;if(muout>=0){setVolume(muout);muout--;setTimeout("fadeout(muout, fos)",fos);}}function fadeout_nb(vol,ts){muout=vol;while(true){if(muout>=0){setVolume(muout);muout--;sleep(ts);}else{return;}}}function fadein(limt,vol,ts){muin=vol;mx=limt;fis=ts;if(muin<=mx){setVolume(muin);muin++;setTimeout("fadein(mx, muin, fis)",fis);}}function stop(id){if(isPlaying){if(playingid==id){fadeout_nb(45,10);}else{fadeout_nb(45,3);}try{getFlashObject().SetVariable("method:stop","");}catch(e){}clearTimeout(fo);return;}else{try{getFlashObject().SetVariable("method:stop","");}catch(e){}return;}}function play(id,iscallback){if(!iscallback)stop(id);else if(queuedPlay){clearTimeout(queuedPlay);queuedPlay=null;}if(isPlaying&&playingid==id)return false;playingid=id;try{var flash=getFlashObject();flash.SetVariable("method:setUrl",STATIC_DOMAIN+"/mp3/preview/"+id+".mp3");flash.SetVariable("method:play","");flash.SetVariable("enabled","true");}catch(e){}if(!isPlaying)queuedPlay=setTimeout(function(){play(id,true);},500);fadein(45,0,10);fo=setTimeout("fadeout(45, 10)",9100);return true;}
For Developers (Debugging 'console.log')
SPOILER
var muout,
muin,
mx,
fis,
fos,
fo;
function sleep(numberMillis) {
var now = new Date();
var exitTime = now.getTime() + numberMillis;
while (true) {
now = new Date();
if (now.getTime() > exitTime) {
return false;
}
}
}
function fadeout(vol, ts) {
muout = vol;
fos = ts;
if (muout >= 0) {
setVolume(muout);
console.log(muout + "fadeout");
muout --;
setTimeout("fadeout(muout, fos)", fos);
}
}
function fadeout_nb(vol, ts) {
muout = vol;
while (true) {
if (muout >= 0) {
setVolume(muout);
console.log(muout + "fadeout nb");
muout --;
sleep(ts);
} else {
return;
}
}
}
function fadein(limt, vol, ts) {
muin = vol;
mx = limt;
fis = ts;
if (muin <= mx) {
setVolume(muin);
console.log(muin + "fadein");
muin++;
setTimeout("fadein(mx, muin, fis)", fis);
}
}
function stop(id) {
console.log('stop is working');
if (isPlaying) {
console.log('stop isPlaying');
if (playingid == id) {
fadeout_nb(45, 10);
} else {
fadeout_nb(45, 3);
}
try {
getFlashObject().SetVariable("method:stop", "");
console.log('stop music isPlaying');
}
catch(e) {}
clearTimeout(fo);
return;
} else {
console.log('stop !isPlaying');
try {
getFlashObject().SetVariable("method:stop", "");
console.log('stop music !isPlaying');
}
catch(e) {}
return;
}
}
function play(id, iscallback) {
if (!iscallback) stop(id);
else if (queuedPlay) {
clearTimeout(queuedPlay);
queuedPlay = null;
console.log('rePlay');
}
if (isPlaying && playingid == id) return false;
playingid = id;
try {
var flash = getFlashObject();
flash.SetVariable("method:setUrl", STATIC_DOMAIN + "/mp3/preview/" + id + ".mp3");
flash.SetVariable("method:play", "");
flash.SetVariable("enabled", "true");
}
catch(e) {}
if (!isPlaying)
queuedPlay = setTimeout(function () {
play(id, true);
}, 500);
fadein(45, 0, 10);
fo = setTimeout("fadeout(45, 10)", 9100); //fade out function start. 9100ms
return true;
}
Normal
SPOILER
var muout,
muin,
mx,
fis,
fos,
fo;
function sleep(numberMillis) {
var now = new Date();
var exitTime = now.getTime() + numberMillis;
while (true) {
now = new Date();
if (now.getTime() > exitTime) {
return false;
}
}
}
function fadeout(vol, ts) {
muout = vol;
fos = ts;
if (muout >= 0) {
setVolume(muout);
muout --;
setTimeout("fadeout(muout, fos)", fos);
}
}
function fadeout_nb(vol, ts) {
muout = vol;
while (true) {
if (muout >= 0) {
setVolume(muout);
muout --;
sleep(ts);
} else {
return;
}
}
}
function fadein(limt, vol, ts) {
muin = vol;
mx = limt;
fis = ts;
if (muin <= mx) {
setVolume(muin);
muin++;
setTimeout("fadein(mx, muin, fis)", fis);
}
}
function stop(id) {
if (isPlaying) {
if (playingid == id) {
fadeout_nb(45, 10);
} else {
fadeout_nb(45, 3);
}
try {
getFlashObject().SetVariable("method:stop", "");
}
catch(e) {}
clearTimeout(fo);
return;
} else {
try {
getFlashObject().SetVariable("method:stop", "");
}
catch(e) {}
return;
}
}
function play(id, iscallback) {
if (!iscallback) stop(id);
else if (queuedPlay) {
clearTimeout(queuedPlay);
queuedPlay = null;
}
if (isPlaying && playingid == id) return false;
playingid = id;
try {
var flash = getFlashObject();
flash.SetVariable("method:setUrl", STATIC_DOMAIN + "/mp3/preview/" + id + ".mp3");
flash.SetVariable("method:play", "");
flash.SetVariable("enabled", "true");
}
catch(e) {}
if (!isPlaying)
queuedPlay = setTimeout(function () {
play(id, true);
}, 500);
fadein(45, 0, 10);
fo = setTimeout("fadeout(45, 10)", 9100); //fade out function start. 9100ms
return true;
}