#Include "fbgfx.bi"
#Include "bass.bi"
Using fb
Screen 13,,2
Type CoordinatesMouse
	x As Integer
	y As Integer
End Type
Type tobject
	As Integer Nb=1
	As Integer current=1
	As BOOL flag
	e As EVENT
	stream As HSTREAM
	mutex As Any Ptr
	Thread As Any Ptr
	MC As CoordinatesMouse
	tagM(1 To 14) As String
End Type
Dim Shared o As tobject
Sub Load_m3u()
	Open "list.m3u" For Input As #1
	If Err>0 Then 
		Print "File list.m3u not found!"
		sleep
		end
	EndIf
	For a As Integer=1 To 14
		Line Input #1,o.tagM(a)
	Next
	Close #1
End Sub
Sub DrawAll(Nb As Integer)
	Dim As Integer count=1
	Line(5,12)-(313,95),8,B
	Line(105,12)-(213,12),0
	Line(5,115)-(313,193),8,B
	Draw String (112,8),"Online Radio",8
	For h As Integer=1 To 2
		For w As Integer=1 To 7
			Circle(w*43-11,h*30+110),13,8
			If Count>9 Then
				If Count<>nb Then
					Draw String (w*43-19,h*30+107),Str(count),8
				Else
					Draw String (w*43-19,h*30+107),Str(count),2
				EndIf
			Else
				If Count<>nb Then
					Draw String (w*43-14,h*30+107),Str(count),8
				Else
					Draw String (w*43-14,h*30+107),Str(count),2
				EndIf
			EndIf
			Count+=1
		Next
	Next
End Sub
Sub DrawMap(text As String Ptr)
	MutexLock(o.mutex)
	Dim As Integer L,L1
	Dim As single FFT(1024)
	o.flag=0
	L1=Len(*text)
	If L1<40 Then
		L=(320-L1*8)\2
	Else
		L=0
	EndIf
	Do
		L+=1
		If L=320 Then L=-(L1*8)
		DrawAll(o.current)
		Draw String (L,101),*text,8	
		Var VCH=BASS_ChannelGetData(o.stream,@FFT(0),BASS_DATA_FFT2048)
		For a As Integer=0 To 50
			Dim As Integer value=Fix(FFT(a)*500)
			If VCH = -1 Then
				Value=1
			EndIf
			If value>60 Then value=60
			Line(10+(a*2),80-value)-step(1,value),2,BF
			Line(110+(a*2),80-value)-step(-1,value),2,BF
			Line(210+(a*2),80-value)-step(-1,value),2,BF
		Next
		PCopy
		Sleep 20
		Cls()
		If o.flag=2 Then
			end
		EndIf
	Loop Until o.flag=1
	MutexUnLock(o.mutex)
End Sub
Sub ClickEvent()
	Dim As Integer count
	Getmouse(o.MC.x,o.MC.y)
	For h As Integer=1 To 2
		For w As Integer=1 To 7
			count+=1
			If o.MC.x>=w*43-24 And o.MC.x<=w*43+2 And o.MC.y>=h*30+97 And o.MC.y<=h*30+123 Then
				o.flag=1
				o.current=count
				o.Thread=ThreadCreate(Cast(Any Ptr,@DrawMap),@o.tagM(count))
				BASS_StreamFree(o.stream)
				o.stream=BASS_StreamCreateURL(o.tagM(count), 0, 0, 0, 0)
				BASS_ChannelPlay(o.stream,0)
			EndIf
		Next
	Next
End Sub
Sub main()
	BASS_Init(-1, 44100, 0,0,0)
	Load_m3u()
	DrawAll(1)
	o.stream=BASS_StreamCreateURL(o.tagM(1), 0, 0, 0, 0)
	If o.stream<>0 Then
		BASS_ChannelPlay(o.stream,0)
	EndIf
	o.mutex = MutexCreate
	o.Thread=ThreadCreate(Cast(Any Ptr,@DrawMap),@o.tagM(1))
	Do
		If (ScreenEvent(@o.e)) Then
			Select Case o.e.type
				Case EVENT_MOUSE_BUTTON_RELEASE
					ClickEvent()
				Case EVENT_WINDOW_CLOSE 
					o.flag=2
			End Select
		End If
	Loop
End Sub
main()

