Hello, I am trying to call an audio file using the onload event. I am able to do it using the media player plugin but I need to be able to call it without the use of a plugin and have play directly in the browser. I think the <audio> tag and html 5 have something to do with it but I am unfamiliar with it. Here is what I got:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
<head>
<!-- Note: you must schedule a task in windows task scheduler to launch html doc -->
<script type="text/javascript"><!--
var callAudio = function(soundfile) {
document.getElementById("sound").innerHTML=
"<embed src=\""+soundfile+"\" hidden=\"true\" autostart=\"true\" loop=\"false\" />";
}
//-->
</script>
<script type="text/javascript">
<!--
var d=new Date();
var hours=d.getHours();
var minutes=d.getMinutes();
var seconds=d.getSeconds();
document.write("<br />"+hours + ":" + minutes +":"+ seconds+"<br />");
var greeting = function()
{
if (hours >=4 && hours <12) {
greeting =(callAudio('sounds/goodMorning.wma'));
}
if (hours >=12 && hours <17) {
greeting = (callAudio('sounds/goodAfternoon.wma'));
}
if (hours >=17 && hours <23) {
greeting = (callAudio('sounds/goodEvening.wma'));
}
if (hours >=23 && hours !==3) {
greeting = (callAudio('sounds/goToSleep.wma'));
}
if (hours <=3 && hours !==4) {
gretting = (callAudio('sounds/goToSleep.wma'));
}
}
var theDay=d.getDay();
switch (theDay)
{
case 5:
document.write("<b>Finally Friday</b>");
break;
case 6:
document.write("<b>Super Saturday</b>");
break;
case 0:
document.write("<b>Sleepy Sunday</b>");
break;
case 1:
document.write("<b>Back to the grind Monday</b>");
break;
case 2:
document.write("<b>Another day in paradise Tuesday</b>");
break;
case 3:
document.write("<b>Over the hump Wednesday</b>");
break;
default:
document.write("<b>I'm really looking forward to this weekend!</b>");
}
//-->
</script>
</head>
<body onload="greeting();">
<span id="sound"></span>
</body>
</html>