I re-edited this code to work better. I even added a loop option. Just hit the L key.
It is quirky when you hit keys because of the fact that there is no timer built in to stop a key from being pressed more then once in a specified amount of time.
But all in all this looks for a music folder. If it does not find one it creates it for you. You then put your MP3 music in there. I limited this to
songLimit = 50. You can change that obviously.
Theoretically, it should loop forever with the listed music you have in the music folder when it first starts up.
cls
Global t = -1
Global b = 0
Global songLimit = 50
DIM mList$(songLimit)
global currentpatha$
global currentpathb$
global soundVolume# = 100.0
global loopthemusic = 0
currentpatha$ = GET DIR$()
if path exist(currentpatha$ + \"\\music\\\") = 0
set text size 27
center text 325,165, \"Music folder created.\"
center text 325,195, \"Then restart player.\"
center text 325,225, \"Put MP3 files into folder to play music.\"
make directory \"music\"
WAIT KEY
end
endif
currentpathb$ = currentpatha$ + \"\\music\\\"
set dir currentpathb$
find first
repeat
if get file type() = 0
t = t + 1
b = b + 1
mList$(t) = get file name$()
ENDIF
find next
until get file type() = -1 or b > songLimit - 1
set dir currentpatha$
set cursor 0, 0
if b < 1
set text size 27
center text 325,165, \"No music was found\"
WAIT KEY
end
ENDIF
if b > 0
cls
set window size 400,400
t = 0
load music currentpathb$ + mList$(t),1
line 0,50,650,50
line 0,55,650,55
line 325,0,325,350
set text size 50
center text 150,5, \"Action\"
center text 475,5, \"Key\"
set text size 27
line 0,100,650,100
center text 150,65, \"Play/Restart\"
center text 475, 65, \"P\"
line 0,150,650,150
center text 150,115, \"Pause/Resume\"
center text 475, 115, \"Space Bar / R\"
line 0,200,650,200
center text 150,165, \"Mute\"
center text 475, 165, \"M\"
line 0,250,650,250
center text 150,215, \"Un-Mute\"
center text 475, 215, \"U\"
line 0,300,650,300
center text 150,265, \"Volume Up\"
center text 475, 265, \"Up Arrow\"
line 0,350,650,350
center text 150,315, \"Volume Down\"
center text 475, 315, \"Down Arrow\"
set text size 70
center text 325,373, \"Muzack MP3 Player\"
set text size 27
INK RGB(100,100,100),RGB(0,0,0)
center text 325,425, \"By Confused1612 : Edited by JackDawson\"
`The above draws the instructions box
INK RGB(100,0,0),RGB(0,0,0)
box 0, 350, 640, 380
INK RGB(100,200,100),RGB(0,0,0)
center text 325,350, mList$(t)
INK RGB(100,200,100),RGB(0,0,0)
center text 325,450, \"Music Loop OFF\"
play music 1
soundVolume# = 100.0
set music volume 1, soundVolume#
set music volume 1, soundVolume#
`The above sets up the volume control and starts the music
do
while music playing (1) = 1
`The above makes sure the following only works while the music is playing
if upkey() = 1
soundVolume# = soundVolume# + 0.05
if soundVolume# > 100.0 then soundVolume# = 100.0
set music volume 1, soundVolume#
set music volume 1, soundVolume#
endif
`The above ups the volume when the up key is pressed
if downkey() = 1
soundVolume# = soundVolume# - 0.05
if soundVolume# < 0.0 then soundVolume# = 0.0
set music volume 1, soundVolume#
set music volume 1, soundVolume#
endif
`The above lowers the volume when the up key is pressed
if rightkey() = 1
stop music 1
Delete Music 1
t = t + 1
if t > b - 1 then t = b - 1
load music currentpathb$ + mList$(t),1
wait 1
play music 1
INK RGB(100,0,0),RGB(0,0,0)
box 0, 350, 640, 380
INK RGB(100,200,100),RGB(0,0,0)
center text 325,350, mList$(t)
endif
if leftkey() = 1
stop music 1
Delete Music 1
t = t - 1
if t < 1 then t = 0
load music currentpathb$ + mList$(t),1
wait 1
play music 1
INK RGB(100,0,0),RGB(0,0,0)
box 0, 350, 640, 380
INK RGB(100,200,100),RGB(0,0,0)
center text 325,350, mList$(t)
endif
if keystate(50) = 1
set music volume 1, 0.0
set music volume 1, 0.0
endif
`The above mutes the volume when the M key is pressed
if keystate(38) = 1
loopthemusic = loopthemusic + 1
if loopthemusic > 1 then loopthemusic = 0
INK RGB(0,0,0),RGB(0,0,0)
box 0, 455, 640, 480
if loopthemusic = 0
INK RGB(100,200,100),RGB(0,0,0)
center text 325,450, \"Music Loop OFF\"
endif
if loopthemusic = 1
INK RGB(100,200,100),RGB(0,0,0)
center text 325,450, \"Music Loop ON\"
endif
endif
`The above loops or unloops the music list when the L key is pressed
if keystate(22) = 1
set music volume 1, soundVolume#
set music volume 1, soundVolume#
endif
`The above unmutes the volume when the U key is pressed
if SpaceKey() = 1
Pause music 1
endif
`The above pauses the music when the Space key is pressed
if keystate(25) = 1
stop music 1
wait 1
play music 1
endif
`The above restarts the music from the beginning
endwhile
while music paused(1) = 1
`The above makes sure the following only works while the music is not playing
if keystate(19) = 1
Resume music 1
endif
`The above unpauses the music when the R key is pressed
if keystate(25) = 1
play music 1
endif
`The above restarts the music from the beginning
endwhile
if loopthemusic = 0
stop music 1
Delete Music 1
end
else
stop music 1
Delete Music 1
t = t + 1
if t > b - 1 then t = 0
load music currentpathb$ + mList$(t),1
wait 1
set music volume 1, soundVolume#
set music volume 1, soundVolume#
play music 1
INK RGB(100,0,0),RGB(0,0,0)
box 0, 350, 640, 380
INK RGB(100,200,100),RGB(0,0,0)
center text 325,350, mList$(t)
endif
loop
endif
if b > 0
stop music 1
Delete Music 1
ENDIF
end
The original coder and thread is here :
http://forum.thegamecreators.com/?m=forum_view&t=194806&b=1
This was compiled and tested to work with the U77 DarkBasic Pro compiler on Windows 7 x64 Bit computer.
matrix1 DLL plugins MIGHT be needed. I am not sure. But if they are needed, look here :
http://forum.thegamecreators.com/?m=forum_view&t=85209&b=18