Click to See Complete Forum and Search --> : playing audio in an html page


designxperts.net
August 31st, 2006, 09:04 AM
i have some HTML pages on a website and need to play different audio files through out the pages ... what i need is a way for the user to click on something to hear the audio file (either a button or an embedded player ) also i'd like it to work with most browsers i tried this media player object but it's not working right :

<object width="262" height="63" classid="clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6" id="WindowsMediaPlayer1" align="middle">
<param name="URL" value="audio/04 Faatiha.wav" />
<param name="DefaultFrame" value="mainFrame" />
<param name="AutoStart" value="0" />
<param name="playCount" value="1" />
<param name="windowlessVideo" value="1" />
<param name="Stretchtofit" value="1" />
<param name="showstatusbar" value="true" />
<embed type="video/x-ms-asf-plugin" pluginspage="http://www.microsoft.com/Windows/
Downloads/Contents/Products/MediaPlayer/" src="audio/04 Faatiha.wav"
name="MediaPlayer" width="270" height="65" showstatusbar="1"> </embed>
</object>

PeejAvery
August 31st, 2006, 11:57 AM
You don't create an audio file with an object tag, you only use embed.

To do what you want, you also need a DIV.
<script language="JavaScript">
function playaudio(file){
var divaudio = document.getElementById('divaudio');
divaudio.innerHTML = "<EMBED src='" + file + "' volume='100' hidden='true' autostart='true'>";
}
</script>

<div id="divaudio" style="visibility:hidden"></div>
<input type="button" value="Play" onclick="playaudio('plan.wav')">

designxperts.net
August 31st, 2006, 02:44 PM
Thanks that worked fine for the .wav files is there something for the .mp3?

PeejAvery
August 31st, 2006, 03:20 PM
Same thing. Just change your file to an MP3.

If the codec is strange, the browser may not find it compatible to play. MP3 will completely depend on the browser. No JavaScript coding can make that difference.

HanneSThEGreaT
September 8th, 2006, 02:45 AM
I know this thread is solved, but I have something to add.
There is a tag called <BGSOUND>.
<HTML>
<HEAD>
<TITLE> Play </TITLE>
</HEAD>
<BODY>
<BGSOUND SRC="MasterOfPuppets.mid" LOOP=10>
</BODY>
</HTML>

PeejAvery
September 8th, 2006, 08:38 AM
I know this thread is solved, but I have something to add.
There is a tag called <BGSOUND>.
True, but you must remember support. Personally, I would stay away from it.

It is not a universal tag and not even considered a true HTML tag. It is not supported on Safari, and Netscape recommends that you use <embed>.

HanneSThEGreaT
September 8th, 2006, 08:46 AM
True, but you must remember support. Personally, I would stay away from it.

It is not a universal tag and not even considered a true HTML tag. It is not supported on Safari, and Netscape recommends that you use <embed>.
Ah, OK I see!
I genuinely thought it was a universal tag. I guess I was misinformed.
Sorry about that:blush:

PeejAvery
September 8th, 2006, 11:44 AM
Don't worry about it. Still good investigation.