
color_r=color.new(255,0,0)

rcol={}
rcol[1]={x=31,y=193,w=40,h=40}
rcol[2]={x=94,y=193,w=40,h=40}
rcol[3]={x=155,y=193,w=40,h=40}
rcol[4]={x=216,y=193,w=40,h=40}
rcol[5]={x=283,y=193,w=40,h=40}
rcol[6]={x=352,y=193,w=40,h=40}
rcol[7]={x=415,y=193,w=40,h=40}


volumen_s=130

function reproductor(carga)
liberar(15)
if not carga then
	o=sound.load(workDir[pos_tarea].name)
	if files.ext(workDir[pos_tarea].name)=="mp3" then
		mp3=true
	else
		mp3=false
	end
	o:pause(1)
	namemusic=files.nopath(workDir[pos_tarea].name)
	if mp3 then 
		tabla_sound=sound.id3(workDir[pos_tarea].name)
	else
		tabla_sound=nil
	end
end
recorrido=0
o:play(1)
volumen_e=1
vol_e=false
info=false

while true do
controls.read()

fondo_wm:blit(0,0)


screen.print(26,30,namemusic:sub(1,math.min(20,#namemusic)),0.8,negro,0)
if mp3 then screen.print(350,31,math.floor(o:duration()/600)/100 .."'",0.7,negro,0) end

indicador_wm:blit(o:percent()*4+30,245)

if controls.press("cross") then
	if col(p,{x=30,y=255,w=400,h=20}) then
		o:percent((p.x-30)/4)
	end
	if col(p,rcol[1]) then
		if vol_e then
			vol_e=false
		else
			vol_e=true
			volumen=o:volume()
		end
	elseif col(p,rcol[2]) then
		recorrido=o:percent()
	elseif col(p,rcol[6]) then
		recorrido=o:percent()
	elseif col(p,rcol[3]) then
		o:pause(1)
	elseif col(p,rcol[4]) then
		if not o:playing() then
			o:play(1)
		else
			o:pause(0)
		end
	elseif col(p,rcol[5]) then
		recorrido=0
		o:percent(recorrido)
		o:pause(1)
	elseif col(p,rcol[7]) then
		if mp3 then
			if info then
				info=false
			else
				info=true
				color_r=color.new(255,0,0,100)
			end
		end
	end
end

if controls.cross() then

	if col(p,rcol[2]) then
		recorrido=recorrido-0.4
		o:percent(recorrido)
	elseif col(p,rcol[6]) then
		recorrido=recorrido+0.4
		o:percent(recorrido)
	end
	
	if col(p,close) then
		sistema("Reproductor",true)
	elseif col(p,saveclose) then
		sistema("Reproductor")
	end
end

if info then
	if math.random(1,100)==1 then
		color_r=color.new(math.random(50,255),math.random(50,255),math.random(50,255),80)
	end
	o:blit("wave",5,49,469,156,color_r)
	screen.print(70,80,"Título: "..tabla_sound.title:sub(math.min(40,#tabla_sound.title)),0.6,negro,0)
	screen.print(70,100,"Artista: "..tabla_sound.artist,0.6,negro,0)
	screen.print(70,120,"Año: "..tabla_sound.year,0.6,negro,0)
	screen.print(70,140,"Album: "..tabla_sound.album,0.6,negro,0)
	screen.print(70,160,"Duración: "..tabla_sound.length.." ''",0.6,negro,0)
else
	if math.random(1,100)==1 then color_r=color.new(math.random(50,255),math.random(50,255),math.random(50,255)) end
	o:blit("wave",5,49,469,140,color_r)
end

if vol_e then
	draw.fillrect(42,131,16,60,blanco)
	draw.fillrect(42,198-volumen/3,16,2,azul)
	draw.rect(42,131,16,60,negro)
	if controls.cross() and col(p,{x=42,y=131,w=16,h=60}) then
		volumen=200-(p.y-131)*3
		o:volume(volumen)
	end
	if controls.press("circle") then
		vol_e=false
	end
end

if controls.start() then sistema("Reproductor") end

puntero()

screen.flip()
end
end
