Share my very simple music player I wrote a long time ago because I thought it could be useful if one wants a lightweight but fully-featured music player without having to rewrite it. grin

Just plug the code in your projects and run - no additional files or dependencies required. And you can write a GUI that makes use of the functions, for example, one GUI button that use mpNext(), which will cycle to the next song in the list.

mpLoad(STRING *scan_path, STRING *scan_ext) must first be called to determine which directory to scan and the file extension, for example
Code:
mpLoad( "./sound/music/", "*.mp3" );



Header :
Code:
TEXT *mpPool = { strings ( 1000 ); } // Maximum of 1000 songs
int mpCount = 0, mpRandomize = 1, mpSongs, mpPauseMark;
var mpHandle;

var MainMenuMusicHndl;
void mpLoad(STRING *, STRING *);
void mpUnload();
void mpPrev();
void mpNext();
void mpPause();
void mpResume();
void mpPlay(STRING *);



Code:
/*
--------------------------------------------------
void mpLoad(STRING *scan_path, STRING *scan_ext)

Desc:

Returns: -
--------------------------------------------------
*/
void mpLoad(STRING *scan_path, STRING *scan_ext) {

STRING *_scan_path = str_create(scan_path); // Prevent modification of the original string

mpSongs = txt_for_dir(mpPool, str_cat(_scan_path,scan_ext) );
while(proc_status(txt_for_dir)) wait(1);

str_remove(_scan_path);

}

/*
--------------------------------------------------
void mpPlay(STRING *songName)

Desc:

Returns: -
--------------------------------------------------
*/
void mpPlay(STRING *songName) {

if(media_playing(mpHandle)) media_stop(mpHandle);
if(mpCount > mpSongs - 1 || mpCount < 0) return;

str_cpy(_mpSongTemp,songName);
str_trunc(_mpSongTemp, str_len( 4 )-1 );
str_cpy(mpSongTemp,PATH_MUSIC);
str_cat(mpSongTemp,songName);

str_for_num(_mpCount, mpCount); // strcpy is unnecessary here

mpHandle = media_play(mpSongTemp,NULL,VOL_MUSIC);

while(media_playing(mpHandle)) wait(1);
mpNext();

}

/*
--------------------------------------------------
void mpNext()

Desc:

Returns: -
--------------------------------------------------
*/
void mpNext() {

if(event_type == EVENT_RELEASE) return;

if(mpCount < mpSongs) {

if(mpRandomize) mpCount = (int) random(mpSongs);
else mpCount += 1;
mpPlay( (mpPool.pstring)[mpCount] );

}

}

/*
--------------------------------------------------
void mpPrev()

Desc:

Returns: -
--------------------------------------------------
*/
void mpPrev() {

if(event_type == EVENT_RELEASE) return;

if(mpCount >= 0) {

if(mpRandomize) mpCount = (int) random(mpSongs);
else mpCount -= 1;
mpPlay( (mpPool.pstring)[mpCount] );

}

}

/*
--------------------------------------------------
void mpPause()

Desc:

Returns: -
--------------------------------------------------
*/
void mpPause() {

if(event_type == EVENT_RELEASE) return;

if(media_playing(mpHandle)) {

media_pause(mpHandle);
mpPauseMark = 1;

}

}

/*
--------------------------------------------------
void mpResume()

Desc:

Returns: -
--------------------------------------------------
*/
void mpResume() {

if(event_type == EVENT_RELEASE) return;

if(mpPauseMark) media_start(mpHandle);

}