Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamically change embedded sound sources

Status
Not open for further replies.

awaresoft

Programmer
Feb 16, 2002
373
DE
Anyone know of a way to dynamically change the source (src) of an embedded sound using Javascript?

I would like my users to be able to change certain sound effects without having to "embed" the full set of sound effects in a page and without having to reload the page.

Here's how I embed my sounds now:

<embed
id=&quot;audioSoundEffect&quot;
name=&quot;audioSoundEffect&quot;
src=&quot;soundeffect.wav&quot;
hidden=&quot;true&quot;
loop=&quot;false&quot;
autostart=&quot;false&quot;>
</embed>

I was thinking along the lines of the following which does not work (IE 6 under Windows 2000):

document.audioSoundEffect.setAttribute('src','
Any ideas?

Thanks!
Malcolm
 
Code:
document.getElementById('audioSoundEffect').src = '[URL unfurl="true"]http://mysite.com/sounds/newsound.wav';[/URL]

Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.
 
Dwarfthrower,

Thanks for responding to my question. I tried your suggestion and it did not work. No error message - but no change in sound.

I placed an alert() link on my page and the correct file names are shown for the src property before and after I change its value. Its as if the sound file is being cached by IE and not being updated?

alert( document.all.audioSoundEffect.src );

I'm using IE 6.0.2800 SP1. Can you confirm that your suggestion works on your side?

Thanks again for your help!
Malcolm

 
Here's what I've done in the past:
Code:
<html>
<head>
<script>
function playSound(strSoundFile){
 document.getElementById('audioSoundEffect').src = '#';
 document.getElementById('audioSoundEffect').src = strSoundFile;
}
</script>
</head>

<body>
<bgsound id=&quot;audioSoundEffect&quot; src=&quot;#&quot; loop=1>
<button onclick=&quot;playSound('[URL unfurl="true"]http://mysite.com/sounds/newsound.wav')&quot;>Click[/URL] Me</button>
</body>
</html>

Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top