[thelist] random image+sound " popup"
Jeroen Wijers
info at internetvraagbaak.nl
Tue May 17 14:07:51 CDT 2005
>
>> I am looking for a script/example that does something like this:
>> randomly in time show and image somewhere ( layer technique
>> is fine even not all browser like it ), and plays a sound....
>
> Jeroen,
>
> You'll find out soon enough that the whole "Plays a sound" part of your
> question is not as trivial as it seems. Implementing a cross platform
> sound
> solution is not straightforward.
>
> That being said, here's one that works in a good number of browsers (IE,
> Moz, Opera). Code is not object-oriented, on purpose, and only truly
> supports playing one sound at a time:
>
> var sounds = new Object();
> var playing_sound;
>
> function registerSound(name, filename)
> {
> sounds[name] = filename;
> }
>
> function initSounds()
> {
> document.write('<span id="soundspan">');
> if (navigator.userAgent.indexOf('Opera') == -1)
> for (i in sounds)
> document.write('<embed name="snd_' + i + '" id="snd_' + i + '" src="'
> + sounds[i] + '" loop="false" autostart="false" hidden="true"
> enablejavascript="true" />');
>
> document.write('</span>');
> }
>
> function playSound(name) {
> playing_sound = document.getElementById('snd_' + name);
> // the embedded object won't exist if we are in Opera.
> if (playing_sound)
> {
> try
> {
> playing_sound.Play();
> }
> catch (e)
> {
> // Just catch the error if it happens, please.
> }
> }
> else
> {
> // play sound in Opera
> playOperaSound(name);
> }
> }
>
> function stopSound() {
> if (playing_sound)
> playing_sound.Stop();
> }
>
> function playOperaSound(name) {
> document.all.soundspan.innerHTML = '<embed src="' + sounds[name] + '"
> hidden="true" autostart="true" loop="false" />';
> // sound has started automatically, so clear the div.
> document.all.soundspan.innerHTML = '';
> }
>
>
> Usage:
>
> <script ...>
> registerSound('ding', '/media/ding.wav');
> ...
> playSound('ding');
> </script>
Ow yes that is tricky i know with browser and platforms... thanks a lot!
Jeroen
>
> <><><><><><><><><><>
> Joshua L. Olson
> WAE Tech Inc.
> http://www.waetech.com/
> Phone: 706.210.0168
>
> Monitor bandwidth usage on IIS6 in real-time:
> http://www.waetech.com/services/iisbm/
>
>
> --
>
> * * Please support the community that supports you. * *
> http://evolt.org/help_support_evolt/
>
> For unsubscribe and other options, including the Tip Harvester
> and archives of thelist go to: http://lists.evolt.org
> Workers of the Web, evolt !
>
More information about the thelist
mailing list