Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 9th, 2004, 08:35 AM
Friend of Wrox
 
Join Date: May 2004
Location: , , .
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Default Wav Files

Hi People,

Is it possible to build an array of embedded wav files? I want to run a for loop against the number of wav files and combine this with Javascripts random() function to access a random wav file each time the page is loaded.

Any help is much appreciated.
Thanks
interrupt

__________________
\'sync\' <cr>
The name specified is not recognized as an internal or external command, operable program or batch file.
 
Old August 9th, 2004, 04:05 PM
Authorized User
 
Join Date: Aug 2004
Location: Chicago, IL, USA.
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here's one way to do it:

// Dump the file names of the sounds you want to play into an array
var sounds= new Array(5)
sounds[0]="hello.wav";
sounds[1]="gun.wav";
sounds[2]="cow.wav";
sounds[3]="rain.wav";
sounds[4]="other.wav";

// randomly select a sound
var rndSound = Math.floor(Math.random()*5);
var wavSrc = sounds[rndSound];

// use the document.write method to write the embed to the page with the proper source file selected
document.write("EMBED src='"+wavSrc+"'>");

You can get a lot fancier, but that should get the job done.





Similar Threads
Thread Thread Starter Forum Replies Last Post
MIDI to .WAV BrianWren Other Programming Languages 0 September 1st, 2006 02:07 PM
MIDI to .WAV BrianWren VB How-To 0 September 1st, 2006 02:06 PM
wav compression jothi Pro VB 6 0 April 26th, 2005 02:12 AM
wav jothi Pro VB 6 0 April 25th, 2005 05:36 AM
How do i play midi or wav files in VB.Net? aldwincusi VB How-To 3 April 11th, 2005 03:55 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.