# MP3 player. can someone help me to make it shuffle?

**URL:** <https://forum.kirupa.com/t/mp3-player-can-someone-help-me-to-make-it-shuffle/287569>\
**Category:** flash\
**Created:** [May 3, 2009, 9:19pm UTC](https://forum.kirupa.com/t/mp3-player-can-someone-help-me-to-make-it-shuffle/287569 "2009-05-03T21:19:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![indiannetizen](https://avatars.discourse-cdn.com/v4/letter/i/48db29/32.png) [@indiannetizen](https://forum.kirupa.com/u/indiannetizen)\
**Post date:** [May 3, 2009, 9:19pm UTC](https://forum.kirupa.com/t/mp3-player-can-someone-help-me-to-make-it-shuffle/287569/1 "2009-05-03T21:19:30Z")

</div>

I have a mp3 player source code and i made it work with play, pause, next and previous buttons including volume controller. now i need to add shuffle also to it.

can someone help me?

here is the code. or else someone can give me a flash player with shuffle function and it should be customizable. using xml.

Flash Code:

function adjustVolume()  
{  
var \_\_reg1 = volume\_mc.slider\_mc.\_x \* 2;  
jukebox.setVolume(\_\_reg1);  
}

function nextSong()  
{  
if (songArray[currentIndex + 1])  
{  
++currentIndex;  
}  
else  
{  
currentIndex = 0;  
}

```
jukebox.loadSound(urls[currentIndex],true);
title_txt.text = titles[currentIndex];
paused = false;

```

}

function prevSong()  
{  
if (currentIndex \> 0)  
{  
–currentIndex;  
}  
else  
{  
currentIndex = songArray.length - 1;  
}

```
jukebox.loadSound(urls[currentIndex], true);
title_txt.text = titles[currentIndex];
paused = false;

```

}

var jbx = new XML();  
jbx.ignoreWhite = true;  
var songArray = new Array();  
var urls = new Array();  
var titles = new Array();  
var artists = new Array();  
var currentIndex = 0;  
var volumeInterval;  
var jukebox = new Sound();  
volume\_mc.slider\_mc.onPress = function ()  
{  
startDrag(this, 0, 0, 0, 50, 0);  
volumeInterval = setInterval(adjustVolume, 50);  
}  
;  
volume\_mc.slider\_mc.onRelease = volume\_mc.slider\_mc.onReleaseOutside = function ()  
{  
stopDrag();  
}  
;  
jbx.onLoad = function (success)  
{  
if (success)  
{  
songArray = jbx.firstChild.childNodes;  
i = 0;  
while (i \< songArray.length)  
{  
urls.push(songArray\*.attributes.url);  
titles.push(songArray\*.attributes.title);  
artists.push(songArray\*.attributes.artist);  
++i;  
}

```
    jukebox.loadSound(urls[currentIndex], true);
    title_txt.text = titles[currentIndex];
    artist_txt.text = artists[currentIndex];
    return;
}

title_txt.text = "Out of Order. Try again later.";

```

}  
;  
jbx.load(“jukebox.xml”);  
var currentPosition = 0;  
var paused = false;  
stop\_btn.onRelease = function ()  
{  
currentPosition = 0;  
jukebox.stop();  
paused = true;  
}  
;  
play\_btn.onRelease = function ()  
{  
if (paused)  
{  
jukebox.start(currentPosition);  
paused = false;  
}

}  
;  
pause\_btn.onRelease = function ()  
{  
if (!paused)  
{  
currentPosition = jukebox.position / 1000;  
jukebox.stop();  
paused = true;  
return;  
}

```
if (currentPosition &gt; 0) 
{
    jukebox.start(currentPosition);
    paused = false;
}

```

}  
;  
mute\_btn.onRelease = function ()  
{  
if (jukebox.getVolume() \> 0)  
{  
jukebox.setVolume(0);  
return;  
}

```
jukebox.setVolume(100);

```

}  
;  
next\_btn.onRelease = nextSong;  
prev\_btn.onRelease = prevSong;  
jukebox.onSoundComplete = nextSong;  
sof\_mc.invisible\_btn.onRelease = function ()  
{  
ad\_mc.play();  
}  
;

xml code:

\<?xml version=“1.0” encoding=“ISO-8859-1”?\>  
\<jukebox\>  
\<song title=" " artist=" " url=“radio/19.mp3” /\>  
\<song title=" " artist=" " url=“radio/20.mp3” /\>  
\</jukebox\>
