Skip to main content

Background music for website in Javascript

--------------------------------[start]-------------------------------------- */


ns6 = document.getElementById;
ns = document.layers;
ie = document.all;
//========================[Sound variables - checking for sound] ===================================//
var NSsound = navigator.plugins && navigator.plugins["LiveAudio"];
var IEsound = navigator.plugins && document.all;
var audioEnabled = NSsound || IEsound;

function newContent(layernm,content) {
if (ns6) document.getElementById(layernm).innerHTML=content;
else if (ie) document.all[layernm].innerHTML=content;
else if (ns) {
eval(' document.layers["'+layernm+'"].document.open();');
eval(" document.layers['"+layernm+"'].document.write('"+content+"');");
eval(' document.layers["'+layernm+'"].document.close();');
}
}

//========[crossbrowser init sound]==============//
function makeSoundDiv(soundname,newInnerHTML) {
var oDiv = document.createElement ("DIV");
oDiv.id = soundname;
oDiv.style.position = "absolute";
oDiv.style.left=-2000;
oDiv.innerHTML=newInnerHTML;
document.body.appendChild (oDiv);
delete oDiv; }
//==================================[crossbrowser init sound]========================================//
function init(soundfile,autostart,loopit) {
soundname=soundfile;
var buff='';
if (loopit==null) loopit=false;
if (audioEnabled) {
if (autostart==null) autostart=false;
buff+=' ';
buff+='<BGSOUND src='+soundfile+'>';
buff+=' ';
} else { // try something else
if (autostart==true) autostart=1; else autostart=0;
if (loopit==true) loopit=1; else loopit=0;
buff+=' buff+=' pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" ';
buff+=' Name="obj_'+soundname+'" src='+soundfile+' AutoStart='+autostart+' ShowStatusBar=1 volume=-1 loop='+loopit+' >';
buff+='
';
}
makeSoundDiv(soundname,"");
makeSoundDiv(soundname+"_buffer",buff);
}


function play(soundname,loopit) {
if (document.getElementById(soundname)) newContent(soundname,document.getElementById(soundname+"_buffer").innerHTML);
else init(soundname,true,loopit);
}


/*
all you need is to write play("your_sound_file.midi",true); for loop
or play("your_sound_file.midi",false); for one time play
You do not have to use the init(...) function since it is called from the play(...) function
This script has been tested and work with Internet Explorer, FireFox and Netscape

example below :
*/


play("MainHoonRemix.mp3",false);



//--------------------------------[stop]--------------------------------------
//-->

Comments

Post a Comment

Popular posts from this blog

Android onTouch or onClick

  The decision to use either   onTouch   or   onClick   in an Android application depends on the specific requirements of the application and the behavior that the developer is trying to achieve. onClick  is called when the user taps a view, and is similar to a button press in a traditional desktop interface.  onClick  provides simple click detection, but it doesn't allow for more complex gestures like swipes and pinches. onTouch , on the other hand, provides more detailed information about the touch event and can detect complex gestures like swipes and pinches.  onTouch  gives you a  MotionEvent  which contains information about the touch event, including the position of the touch, the time of the touch, and the action that occurred. If you need to detect simple click events, then  onClick  is sufficient. However, if you need to detect more complex gestures, like swipes and pinches, then  onTouch is a better choice. Also, you can use both  onTouch  and  onClick  together if necess