mrjameer Posted September 11, 2007 Share Posted September 11, 2007 hi, i want to play some audio and video files(separately) randomly.any tutorials or links or any help will be surely appreciated.i search in google.but i dont get any useful links.. thanks mrjameer Quote Link to comment https://forums.phpfreaks.com/topic/68903-play-audiovideo-files-randomly/ Share on other sites More sharing options...
bcoffin Posted September 11, 2007 Share Posted September 11, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/68903-play-audiovideo-files-randomly/#findComment-346359 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.