Above code was made in v5.2 and didn't work anymore in v5.4
A little change did the trick. Here it is for v5.4:
` LOADING RANDOM INGAME MUSIC WITH CONTROLS
` By Dennuz666.com 29-06-2004
dim _music_filename$(100) : ` STORE THE FILENAMES FOR LOADING
dim _music_nr_of_files(1) : ` STORE THE NUMBER OF FILES IN A DIRECTORY
dim _music_load_max(1) : ` HOW MANY SONGS ARE LOADED FROM THE DIRECTORY
` SET VARIABLES AND LOAD MUSIC
_music_load_max(1) = 5
_music_playing = _music_load_max(1)
_load_music("music")
do
` GET KEYPRESS
key = scancode()
if key_on = 1 AND key <> 26 AND key <> 27 then key_on = 0
` CONTROL MUSIC
gosub _control_music
`cls
set cursor 0,400
` PRINT "PLAYING TRACK NUMBER: "+str$(_music_playing(1))
loop
function _load_music(_music_dir$)
print "MAX NUMBER OF FILES: "+str$(_music_load_max(1))
print "DIRECTORY: "+_music_dir$
` GO TO _music_dir$ DIRECTORY
set dir _music_dir$
` CHECK FOR FILES AND ADD THEM TO VARIABLES
_music_nr_of_files(1) = 0
perform checklist for files
for a = 1 to checklist quantity()
if right$(checklist string$(a),3) = "mp3"
inc _music_nr_of_files(1),1
_music_filename$(_music_nr_of_files(1)) = checklist string$(a)
print "FILES AVAILABLE: "+_music_filename$(_music_nr_of_files(1))
endif
next a
print "NUMBER OF FILES: "+str$(_music_nr_of_files(1))
` RANDOM PICK NUMBER OF FILES AND LOAD THEM INTO MEMORY (_music_load_max)
if _music_nr_of_files(1) > _music_load_max(1)
for a = 1 to _music_load_max(1)
` RANDOMIZE AND PICK A FILENUMBER
randomize timer()
file = rnd(_music_load_max(1))+1
` LOAD MUSIC
load music _music_filename$(file),a
print "FILE LOADED: "+_music_filename$(file)
` DELETE THE ELEMENT SO NO MUSIC CAN BE LOADED TWICE
array delete element _music_filename$(1),file
dec _music_nr_of_files(1),1
next a
else
`IF THERE AREN'T ENOUGH FILES THEN LOAD ALL YOU'VE GOT
_music_load_max(1) = _music_nr_of_files(1)
for a = 1 to _music_load_max(1)
load music _music_filename$(a),a
print "FILE LOADED: ALL"
next a
endif
`GO BACK TO ROOT
set dir ".."
endfunction
_control_music:
` CHECK IF A MUSIC IS PLAYING
_music_check = 0
for a = 1 to _music_load_max(1)
if music playing(a) = 1 then _music_check = a
next a
` IF NOTHING IS PLAYING THEN PLAY NEXT SONG
if _music_check = 0
inc _music_playing
if _music_playing > _music_load_max(1) then _music_playing = 1
play music _music_playing
endif
`CONTROL MUSIC WITH KEYS
` KEY = 0 (Music OFF)
if key = 11
set music volume _music_playing,0
endif
` KEY = - (Volume down)
if key = 12 and music volume(_music_playing) > 0
set music volume _music_playing,(music volume(_music_playing)-1)
endif
` KEY = + (Volume up)
if key = 13 and music volume(_music_playing) < 100
set music volume _music_playing,(music volume(_music_playing)+1)
endif
`KEY = ] (Next track)
if key = 27 AND key_on = 0
stop music _music_playing
key_on = 1
endif
`KEY = [ (Prev track)
if key = 26 AND key_on = 0
stop music _music_playing
dec _music_playing,2
if _music_playing < 0 then _music_playing = _music_load_max(1)-1
key_on = 1
endif
return