Jump to content

play audio/video files randomly


mrjameer

Recommended Posts

You can build a javascript array:

 

tunes = new Array;

tunes[0] = "MaryHadALittleLamb.mp3";

tunes[1] = "LondonBridgesFallingDown.mp3";

...

tunes[1000] = "TwinkleTwinkleLittleStar.mp3";

 

Then when your media player loads, you can assign the clip using javascript.

 

 

<embed name="player" id="player" pluginspage="http://www.microsoft.com/windows/windowsmedia/download/" type="application/x-mplayer2" src="" width="320" height="240" ShowControls=1 ShowDisplay=0 ShowStatusBar=0 autostart=1 autorewind=0 ShowPositionControls=1 ShowTracker=0>

</embed>

 

then in your body tag, call a cue function:

 

onload = chooseRandom();

 

chooseRandom could look like this:

 

function chooseRandom() {

var tunesnum = tunes.length - 1;

do {

var randnum = Math.random();

rand1 = Math.round((tunesnum - 1) * randnum) + 1;

} while (rand1 == useRand);

useRand = rand1;

document.getElementById("player").src=tunes[rand1];

        }

 

 

The same should work for vid files.

Make sure you have the path to the files correct in your js array.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.