--vmp3 by mrafenne




menu = Image.load("ms0:/PSP/GAME/vmp3v1/images/fondvis/vmp3.png")
font = Font.load("ms0:/PSP/GAME/vmp3v1/images/ALIEN5.TTF")
font:setPixelSizes(14,16)
xim1 = 0
xim2 = 0
white = Color.new(255, 255, 255)
green = Color.new(0, 255, 0)
System.currentDirectory("ms0:/MUSIC/")

fbrowser = {s = 1, fl = System.listDirectory("ms0:/MUSIC/"),ls = 1, sp = 10}
fbrowser.nf = table.getn(fbrowser.fl)
function nomvis1()
xim2 = 0
if preiw == "fasle" and next == "fasle" then
if xim1 <= 0 and xim1 >= 0 then
xim1 = xim1 +8
end
end
end
function exitMenu()
menu = nil
font = nil
mov1 = nil
mov2 = nil
collectgarbage()
end



function runfbrowser()
function nomvis1()
xim2 = 0
if preiw == "fasle" and next == "fasle" then
if xim1 <= 0 and xim1 >= -300 then
xim1 = xim1 +8
end
end
end
nomvis1()
for i = ((fbrowser.ls-1)*fbrowser.sp)+1, fbrowser.ls*fbrowser.sp do
if fbrowser.nf >= i then
screen:fontPrint(font,10,((i-((fbrowser.ls-1)*fbrowser.sp))*25)-10,fbrowser.fl[i].name,white)
elseif fbrowser.nf < i then break end
end
screen:fontPrint(font,10,((fbrowser.s-((fbrowser.ls-1)*fbrowser.sp))*25)-10,fbrowser.fl[fbrowser.s].name,green)


if pad:down() and not oldpad:down() then fbrowser.s = fbrowser.s + 1 end
if pad:up() and not oldpad:up() then fbrowser.s = fbrowser.s - 1 end

if fbrowser.s > fbrowser.nf then fbrowser.s = fbrowser.nf elseif fbrowser.s < 1 then fbrowser.s = 1 end
if fbrowser.s > fbrowser.sp*fbrowser.ls then fbrowser.ls = fbrowser.ls + 1
elseif fbrowser.s < ((fbrowser.ls-1) * fbrowser.sp)+1 then fbrowser.ls = fbrowser.ls - 1 fbrowser.s = (fbrowser.ls)*fbrowser.sp end

if pad:circle() and not oldpad:circle() then
if System.currentDirectory ~= "ms0:/" then
System.currentDirectory("./..")
fbrowser.s = 1
fbrowser.fl=System.listDirectory()
fbrowser.nf=table.getn(fbrowser.fl)
fbrowser.ls = 1
end
end

if pad:cross() and not oldpad:cross() then

if fbrowser.fl[fbrowser.s].directory then
System.currentDirectory(fbrowser.fl[fbrowser.s].name)
fbrowser.s = 1
fbrowser.fl=System.listDirectory()
fbrowser.nf=table.getn(fbrowser.fl)
fbrowser.ls = 1

end

if not fbrowser.fl[fbrowser.s].directory then
if string.lower(string.sub(fbrowser.fl[fbrowser.s].name, -4)) == ".mp3" or string.lower(string.sub(fbrowser.fl[fbrowser.s].name, -4)) == ".MP3" then
playing = 1
Mp3me.load(fbrowser.fl[fbrowser.s].name)
Mp3me.play()

while playing == 1 do

pad = Controls.read()
oldpad = pad

dofile("ms0:/PSP/GAME/vmp3v1/menu.lua")
exitMenu()
if pad:start() then
Mp3me.stop()
System.currentDirectory("ms0:/PSP/GAME/vmp3v1/")
--dofile("script.lua")
end
end
end
end
end
end  


while true do
	
screen:clear()

System.usbDiskModeActivate() 

screen:blit(380,210,menu)

pad = Controls.read()

System.setHigh()

runfbrowser()


screen.waitVblankStart()
screen.flip()
oldpad = pad
end
