MP3 Player

BlitzMax Forums/BlitzMax GUI Programming/MP3 Player

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

A bit too hacky and too much globals but works:

'Source Code created on 09 Aug 2007 00:38:19 with Logic Gui Version 2.1 Build 248
'Glenn Dodd



Global MainWindow:TGadget = CreateWindow:TGadget("Logic_Gui",0,0,1280,968,Null,WINDOW_TITLEBAR|WINDOW_RESIZABLE |WINDOW_MENU |WINDOW_STATUS |WINDOW_CLIENTCOORDS )
Global ChildWindow2:TGadget = CreateWindow:TGadget("ChildWindow2",228,52,487,434,MainWindow:TGadget,WINDOW_TITLEBAR|WINDOW_TOOL |WINDOW_CHILD)
Global Canvas1:TGadget = CreateCanvas:TGadget(11,-12,423,388,ChildWindow2:TGadget,Null)
Global lstDrive:TGadget = CreateListBox:TGadget(11,24,123,133,Canvas1:TGadget,Null)
Global lstFolders:TGadget = CreateListBox:TGadget(12,168,125,206,Canvas1:TGadget,Null)
Global lstFiles:TGadget = CreateListBox:TGadget(157,15,247,313,Canvas1:TGadget,Null)
Global butPlayMe:TGadget = CreateButton:TGadget("Play the Selected File",160,361,127,12,Canvas1:TGadget,BUTTON_PUSH)
Global butStopMe:TGadget = CreateButton:TGadget("Stop the Selected File",360,361,127,12,Canvas1:TGadget,BUTTON_PUSH)


' find all drive names
For i = Asc("C") To Asc("Z")
  Local key:String = Chr(i)+":"
  dir=ReadDir(key)
	If dir
		AddGadgetItem lstDrive, key
	EndIf
Next


Global thisDrive:String
Global thisFolder:String
Global thisFile:String

Global process:TProcess


Function ListAll()
	Local files$[]


	files=LoadDir(thisDrive +  thisFolder,  False)

	Print thisDrive + thisFolder

	ClearGadgetItems lstFolders
	ClearGadgetItems lstFiles

	For t$=EachIn files
		Local f:String = thisDrive + thisFolder + "" + t
		If FileType(f) = 2
			AddGadgetItem lstFolders, t
		Else
			If ExtractExt(f) = "mp3"
				AddGadgetItem lstFiles, t
			EndIf
		EndIf
	Next
EndFunction


Function playMusic()
	Local prg:String = "mplayer\mplayer.exe"
	Local file:String = thisDrive + thisFolder + "" + thisFile
	
	Local calltext:String  = prg + " " +  Chr(34)+file+Chr(34)
	Print calltext
	
	stopMusic()
	process=CreateProcess(calltext)

	' stop with process.terminate()
	Rem
	Repeat
		If process.status() = 0 Then Exit
		Local error:String = process.err.readline()
		If error <> "" Then
			Print error
		EndIf
	Forever
	End Rem
End Function

Function stopMusic()
	If process Then process.terminate()
EndFunction


Repeat
	WaitEvent()
	Select EventID()
		Case EVENT_WINDOWCLOSE
			Select EventSource()
				Case MainWindow	MainWindow_WC( MainWindow:TGadget )
				Case ChildWindow2	ChildWindow2_WC( ChildWindow2:TGadget )
			End Select

		Case EVENT_GADGETACTION
			Select EventSource()
				Case lstDrive	lstDrive_GA( lstDrive:TGadget , EventData() , EventExtra:Object() )
				Case lstFolders	lstFolders_GA( lstFolders:TGadget , EventData() , EventExtra:Object() )
				Case lstFiles	lstFiles_GA( lstFiles:TGadget , EventData() , EventExtra:Object() )
				Case butPlayMe	butPlayMe_GA( butPlayMe:TGadget )
				Case butStopMe	butStopMe_GA( butStopMe:TGadget )
			End Select

		Case EVENT_GADGETSELECT
			Select EventSource()
				Case lstDrive	lstDrive_GS( lstDrive:TGadget , EventData() , EventExtra:Object() )
				Case lstFolders	lstFolders_GS( lstFolders:TGadget , EventData() , EventExtra:Object() )
				Case lstFiles	lstFiles_GS( lstFiles:TGadget , EventData() , EventExtra:Object() )
			End Select

		Case EVENT_GADGETMENU
			Select EventSource()
				Case lstDrive	lstDrive_GM( lstDrive:TGadget , EventData() , EventExtra:Object() , MainWindow:TGadget )
			End Select

	End Select
Forever

Function MainWindow_WC( Window:TGadget )
	DebugLog "Window MainWindow wants to be closed"
'	HideGadget( Window:TGadget )

	End
End Function

Function ChildWindow2_WC( Window:TGadget )
	DebugLog "Window ChildWindow2 wants to be closed"
'	HideGadget( Window:TGadget )

	End
End Function

Function lstDrive_GA( ListBox:TGadget , Number:Int , Extra:Object )
	DebugLog "ListBox lstDrive double clicked an Item " + Number
    If Number => 0 DebugLog "Selected Text = "+ GadgetItemText( ListBox:TGadget , Number:Int )

	thisDrive = GadgetItemText( ListBox:TGadget , Number:Int )
	thisFolder = ""
	ListAll()

End Function

Function lstFolders_GA( ListBox:TGadget , Number:Int , Extra:Object )
	DebugLog "ListBox lstFolders double clicked an Item " + Number
    If Number => 0 DebugLog "Selected Text = "+ GadgetItemText( ListBox:TGadget , Number:Int )


	If GadgetItemText( ListBox:TGadget , Number:Int ) = ".."
		thisFolder = thisFolder[..thisfolder.findlast("")]
	Else
		thisFolder = thisFolder + "" + GadgetItemText( ListBox:TGadget , Number:Int ) 
	EndIf
	
	ListAll()

End Function

Function lstFiles_GA( ListBox:TGadget , Number:Int , Extra:Object )
	DebugLog "ListBox lstFiles double clicked an Item " + Number
    If Number => 0 DebugLog "Selected Text = "+ GadgetItemText( ListBox:TGadget , Number:Int )
	
End Function

Function butStopMe_GA( Button:TGadget )
	DebugLog "Button butPlayMe was pressed"
	stopMusic()
EndFunction

Function butPlayMe_GA( Button:TGadget )
	DebugLog "Button butPlayMe was pressed"
	playMusic()
End Function

Function lstDrive_GS( ListBox:TGadget , Number:Int , Extra:Object )
	DebugLog "ListBox lstDrive single clicked an Item"
	
End Function

Function lstFolders_GS( ListBox:TGadget , Number:Int , Extra:Object )
	DebugLog "ListBox lstFolders single clicked an Item"
	
End Function

Function lstFiles_GS( ListBox:TGadget , Number:Int , Extra:Object )
	DebugLog "ListBox lstFiles single clicked an Item"
	thisFile = GadgetItemText( ListBox:TGadget , Number:Int )
	' Notify thisDrive + thisFolder + "" + thisFile
	
End Function

Function lstDrive_GM( ListBox:TGadget , Number:Int , Extra:Object , Window:TGadget=Null )
	DebugLog "ListBox lstDrive right clicked an Item"
	
End Function




Put the mplayer in the same directory.

*updated*