Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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.
Reply With Quote
  #2 (permalink)  
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.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 12:55 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.