
song={}

function playlist_f()

if #song<=0 then sistema() end
liberar(20)

while true do
controls.read()
img_escritorio[fondo_escritorio]:blend(0,0,200)
barra_cerrar:blit(0,0)
screen.print(10,5,"PlayList",verde)
actual=0

	
for i=1,math.min(#song,13) do
	if col(p,{x=0,y=27+20*i,w=480,h=15}) then
		actual=i
		draw.fillrect(0,27+20*i,480,15,blanco)
		if song_a==i then 
			screen.print(30,30+20*i,files.nopath(song[i])..repro_endo,0.7,negro,0) 
		else
			screen.print(30,30+20*i,files.nopath(song[i]),0.7,negro,0) 
		end
	else 
		if song_a==i then 
			screen.print(30,30+20*i,files.nopath(song[i])..repro_endo,0.6,blanco,verde) 
		else
			screen.print(30,30+20*i,files.nopath(song[i]),0.6,blanco,verde) 
		end
	end
end


if actual>0 then
	if controls.press("cross") then
		if type(playlist)=="userdata" then playlist:stop() playlist:free() end
		playlist=sound.load(song[song_a])
		song_a=actual
	end
	if controls.press("square") then
		if type(playlist)=="userdata" then
			if song_a==actual then playlist:stop() playlist:free() playlist=nil end
		end
		table.remove(song,actual)
	end
end

if #song==0 then minimizado=false sistema(false,"PlayList") end

if type(playlist)=="userdata" then
	if playlist:playing()==false then playlist:play(4) end
else
	playlist=sound.load(song[song_a])
end

puntero()

if controls.start() then sistema("PlayList") end
if controls.press("cross") then
	if col(p,close) then
		sistema("PlayList",true)
	elseif col(p,saveclose) then
		sistema("PlayList")
	end
end

screen.flip()
end
end


function input_playlist()
if minimizado then

	if rutinas[1].p!="PlayList" and rutinas[2].p!="PlayList" and rutinas[3].p!="PlayList" then
		minimizado=false 
	end
	if playlist==nil then
		if #song>song_a then 
			song_a=song_a+1
		else 
			song_a=1
		end
		playlist=sound.load(song[song_a])
		playlist:play(4)
	else
		if not playlist:playing() then 
			playlist:free()
			playlist=nil
			if #song>song_a then 
				song_a=song_a+1
			else 
				song_a=1
			end
			playlist=sound.load(song[song_a])
			playlist:play(4)
		end
	end
elseif playlist!=nil then
	if type(playlist)=="userdata" then playlist:stop() playlist:free() end
	playlist=nil 
	if rutinas[1].p=="PlayList" then 
		rutinas[2].p=rutinas[1].p
		rutinas[3].p=rutinas[2].p
	elseif rutinas[2].p=="PlayList" then 
		rutinas[3].p=rutinas[2].p
		rutinas[3].p=""
	elseif
		rutinas[3].p=="PlayList" then 
		rutinas[3].p=""
	end
end
end