MP3 OGG und FLAC.
die Prozedur "onMouseOver" habe ich hier aus dem Forum,
und stammt vom Forenmitglied PAMKKKKK, vielen Dank dafür !
benötigt werden die LibzPlay.dll und deren Wrapper von TS-Soft,
auch an Thomas Schulz (TS-Soft) recht schönen Dank.
Für Änderungen und oder Tips was ich besser in der Programm Struktur
machen könnte, bitte melden.
Bitte beachten >>> Ich bin Anfänger <<<
also mich nicht gleich zerreissen. Danke Gruß Thor
Windows Only !
;
PureBasic 5.60
Windows 7 32 Bit,AMD Athlon II X4 640, 4GB Ram DDR3,Geforce 9800GT
Code: Alles auswählen
; Kleiner Audioplayer der folgende Formate abspielen kann :
; MP3 OGG und FLAC.
; die Prozedur "onMouseOver" habe ich hier aus dem Forum,
; und stammt vom Forenmitglied PAMKKKKK, vielen Dank dafür !
; benötigt werden die LibzPlay.dll und deren Wrapper von TS-Soft,
; auch an Thomas Schulz (TS-Soft) recht schönen Dank.
; Für Änderungen und oder Tips was ich besser in der Programm Struktur
; machen könnte, bitte melden.
; Bitte beachten >>> Ich bin Anfänger <<<
; also mich nicht gleich zerreissen. Danke Gruß Thor
; Windows Only !
;
; PureBasic 5.60
; Windows 7 32 Bit,AMD Athlon II X4 640, 4GB Ram DDR3,Geforce 9800GT
IncludeFile "J:\Purebasic531\libzplay.pbi" ; oder Verzeichnis wählen wo sich die libzplay.pbi befindet.
EnableExplicit
Enumeration
#Progress_BarTime
#Progress_Right ; Progressbar Rechts
#Progress_Left ; Progressbar Links
#Pause_Button ; Button Pause
#Stop_Button ; Button Stop
#Exit_Button ; Button Exit
#ListDir_Gadget ; ExplorerTreeGadget
#ListFile_Gadget ; ExplorerListGadget
#ListIcon_Gadget ; ListIconGadget
#Time_ID3Tag_Gadget ; EditorGadget
#Auto_Gadget ; OptionGadget Auto Play
#Time_Gadget ; OptionGadget Random Play
#Single_Gadget ; OptionGadget Single Selection PLay
#String_Gadget ; Test String
#Text_Titel ; Textgadget Titel
#Text_Interpret ; Textgadget Interpret
#Text_Album ; Textgadget Album
#Text_Year ; Textgadget Year
#Text_Time_Total ; Textgadget Total Time
#Text_Time_Real ; Textgadget Real Time
#Text_Time_Format ; Time Format hh:mm:ss
#Text_Time_Format_Real ; Time Format hh:mm:ss
#Text_Format ; Format des Tracks (Mp3,Ogg,Flac)
#Text_Bitrate ; Textgadget Bitrate
#Text_Time_Percent ; Zeit Prozentual
#Text_CpuUsage ; Cpu Auslastung
#Text_Play ; Play Track
#String_Gadget_Play ; StringGadget Play
#String_Gadget_Cpu ; StringGadget Cpu
#String_Gadget_Bitrate ; StringGadget Bitrate
#String_Gadget_Titel ; StringGadget Titel
#String_Gadget_Interpret ; StringGadget Interpret
#String_Gadget_Album ; StringGadget Album
#String_Gadget_Year ; StringGadget Year
#String_Gadget_Total_Time ; StringGadget Total Time
#String_Gadget_Real_Time ; StringGadget Real Time
#String_Gadget_Percent ; Zeit Prozentual
#String_Gadget_Format ; Format Ausgabe
#Open_Win ; Window Handle Number
#Font1 ; Font Verdana 16
#Font2 ; Font Verdana 12
#Font3 ; Font Verdana 8
EndEnumeration
Global gCurrentUsage.d
Global NBSongs.i
Global File$,File_RND$
Global i.i
Global ID3.TID3Info
Global TSI.TStreamInfo
Global TST.TStreamTime
Global THT.TStreamHMSTime
Global TSS.TStreamStatus
Global TotalTrackMS.i,TotalTrackSec.i,TotalTrackMin.i,TotalTrackHour.i
Global Trackpointsecond.i,Trackpointminute .i,Trackpointhour.i,PositionTrackPointsec.i
Global MaxTrackSec.i
Global Indikator.i,Bit_Rate.i,biss$,Beschreibung.s
Global Title_Text$,Artist_Text$,Album_Text$,Year_Text$
Global links.i,rechts.i,status.i,stringplay.i
Global hZPlay = CreateZPlay()
Global PercentageValue.f,RemainValue.f,PauseAktiv.b,RND.i,listfile.i
Declare Exit()
Declare.b onMouseOver(GadgedNr)
Declare loadSongRND(File$)
Declare Start(now)
Declare Level(Bel)
Define Flags_Window = #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_MinimizeGadget
Define Flags_List = #PB_Explorer_NoFolders|#PB_Explorer_NoParentFolder|#PB_Explorer_List|#PB_Explorer_AlwaysShowSelection
OpenWindow(#Open_Win, 0,0, 1024,768,"Audio Player (Mp3,OGG,FLAC)",Flags_Window)
LoadFont(#Font1, "Verdana",12)
LoadFont(#Font2, "Arial",10)
LoadFont(#Font3, "Verdana",8)
SetGadgetFont(#PB_Default, FontID(#Font1))
ButtonGadget(#Pause_Button,256,320,256,64,"Pause")
ButtonGadget(#Stop_Button,512,320,256,64,"Stop Play")
ButtonGadget(#Exit_Button,768,320,256,64,"Exit")
OptionGadget(#Auto_Gadget,5,320,160,25,"One by one Play")
OptionGadget(#Time_Gadget,5,350,160,25,"Random Play")
OptionGadget(#Single_Gadget,5,290,160,25,"Single Selection")
TextGadget(#Text_Play,5,235,100,25,"Play Track")
TextGadget(#Text_Titel,5,10,100,25,"Titel")
TextGadget(#Text_Interpret,5,35,100,25,"Interpret")
TextGadget(#Text_Album,5,60,100,25,"Album")
TextGadget(#Text_Year,5,85,100,25,"Year")
TextGadget(#Text_Format,5,110,100,25,"Format")
TextGadget(#Text_Bitrate,5,135,100,25,"Bitrate")
TextGadget(#Text_Time_Total,5,160,100,25,"Total Time")
TextGadget(#Text_Time_Real,5,185,100,25,"Real Time")
TextGadget(#Text_Time_Format,255,160,120,25,"(hh:mm:ss)")
TextGadget(#Text_Time_Format_Real,255,185,120,25,"(hh:mm:ss)")
TextGadget(#Text_Time_Percent,5,210,100,25,"Percentage")
StringGadget(#String_Gadget_Play,105,235,180,25,"",#PB_String_BorderLess)
StringGadget(#String_Gadget_Titel,105,10,1000,25,"",#PB_String_BorderLess )
StringGadget(#String_Gadget_Bitrate,105,135,270,25,"",#PB_String_BorderLess )
StringGadget(#String_Gadget_Interpret,105,35,1000,25,"",#PB_String_BorderLess )
StringGadget(#String_Gadget_Album,105,60,1000,25,"",#PB_String_BorderLess )
StringGadget(#String_Gadget_Year,105,85,270,25,"",#PB_String_BorderLess )
StringGadget(#String_Gadget_Format,105,110,320,25,"",#PB_String_BorderLess )
StringGadget(#String_Gadget_Total_Time,105,160,150,25,"",#PB_String_BorderLess )
StringGadget(#String_Gadget_Real_Time,105,185,150,25,"",#PB_String_BorderLess )
StringGadget(#String_Gadget_Percent,105,210,120,25,"",#PB_String_BorderLess)
SetGadgetColor(#String_Gadget_Play,#PB_Gadget_BackColor,RGB(240,240,240))
SetGadgetColor(#String_Gadget_Titel,#PB_Gadget_BackColor,RGB(240,240,240))
SetGadgetColor(#String_Gadget_Interpret,#PB_Gadget_BackColor,RGB(240,240,240))
SetGadgetColor(#String_Gadget_Album,#PB_Gadget_BackColor,RGB(240,240,240))
SetGadgetColor(#String_Gadget_Year,#PB_Gadget_BackColor,RGB(240,240,240))
SetGadgetColor(#String_Gadget_Total_Time,#PB_Gadget_BackColor,RGB(240,240,240))
SetGadgetColor(#String_Gadget_Real_Time,#PB_Gadget_BackColor,RGB(240,240,240))
SetGadgetColor(#String_Gadget_Percent,#PB_Gadget_BackColor,RGB(240,240,240))
SetGadgetColor(#String_Gadget_Format,#PB_Gadget_BackColor,RGB(240,240,240))
SetGadgetColor(#String_Gadget_Bitrate,#PB_Gadget_BackColor,RGB(240,240,240))
ProgressBarGadget(#Progress_BarTime,230,210,200,20,0,100, #PB_ProgressBar_Smooth )
ProgressBarGadget(#Progress_Left,984,120,20,172,0,100,#PB_ProgressBar_Vertical)
ProgressBarGadget(#Progress_Right,1004,120,20,172,0,100,#PB_ProgressBar_Vertical)
ExplorerTreeGadget(#ListDir_Gadget,0,384,512,384,"*.mp3;*.ogg;*.flac",#PB_Explorer_NoFiles)
ExplorerListGadget(#ListFile_Gadget,512,384,512,384, "*.mp3;*.ogg;*.flac",Flags_List)
SetGadgetColor(#ListDir_Gadget,#PB_Gadget_BackColor,RGB(240,240,240))
SetGadgetColor(#ListFile_Gadget,#PB_Gadget_BackColor,RGB(240,240,240))
SetGadgetState(#Single_Gadget,1)
For i=3 To 1 Step -1
RemoveGadgetColumn(#ListFile_Gadget,i)
Next
SetGadgetItemAttribute(#ListFile_Gadget,0,#PB_Explorer_ColumnWidth,506)
SetGadgetItemText(#ListFile_Gadget,-1,"Titel auswählen")
SetGadgetFont(#ListDir_Gadget, FontID(#Font2))
SetGadgetFont(#ListFile_Gadget, FontID(#Font2))
SetGadgetFont(#Text_Time_Format, FontID(#Font3))
SetGadgetFont(#Text_Time_Format_Real, FontID(#Font3))
zplay_SetFFTGraphParam(hZPlay, #gpGraphType, #gtArealeftontop)
zplay_SetFFTGraphParam(hZPlay, #gpcolor1, RGB(240,240,240))
zplay_SetFFTGraphParam(hZPlay, #gpcolor2, RGB(240,240,240))
zplay_SetFFTGraphParam(hZPlay, #gpcolor6, RGB(240,240,240))
zplay_SetFFTGraphParam(hZPlay, #gpcolor7, RGB(240,240,240))
zplay_SetFFTGraphParam(hZPlay, #gpcolor3, RGB(240,240,240))
zplay_SetFFTGraphParam(hZPlay, #gpcolor4, RGB(240,240,240))
zplay_SetFFTGraphParam(hZPlay, #gpFFTPoints, 512)
zplay_SetFFTGraphParam(hZPlay, #gpHorizontalScale, #gsLogarithmic)
zplay_SetFFTGraphParam(hzplay, #gpTransparency,25)
zplay_SetFFTGraphParam(hZPlay, #gpWindow, #FWhann)
CreateThread(@Start(),1)
CreateThread(@Level(),2)
AddWindowTimer(#Open_Win,0,350)
Repeat
Select WaitWindowEvent()
Case #PB_Event_Timer
If EventTimer() = 0
If onMouseOver(#ListFile_Gadget) = 1
SetActiveGadget(#ListFile_Gadget)
EndIf
RND = Random(NBSongs,0)
If PositionTrackPointsec >= MaxTrackSec -3; 3 Sekunden vor Ende des Titels wird der nächste geladen...
If GetGadgetState(#Auto_Gadget) = #True
SetGadgetItemState(#ListFile_Gadget,GetGadgetState(#ListFile_Gadget)+1,#PB_Explorer_Selected )
File_RND$ =GetGadgetText(#ListFile_Gadget)+GetGadgetItemText(#ListFile_Gadget,GetGadgetState(#ListFile_Gadget),0)
loadSongRND(File_RND$)
EndIf
EndIf
If PositionTrackPointsec >= MaxTrackSec -3; 3 Sekunden vor Ende des Titels wird der nächste geladen...
If GetGadgetState(#Time_Gadget) = #True
SetGadgetItemState(#ListFile_Gadget,RND,#PB_Explorer_Selected)
File_RND$ =GetGadgetText(#ListFile_Gadget)+GetGadgetItemText(#ListFile_Gadget,GetGadgetState(#ListFile_Gadget),0)
loadSongRND(File_RND$)
EndIf
EndIf
EndIf
Case #PB_Event_Gadget ; in einem Gadget wurde ein Event ausgelöst !
Select EventGadget()
Case #ListDir_Gadget
If EventType() = #PB_EventType_LeftClick
SetGadgetText(#ListFile_Gadget,GetGadgetText(#ListDir_Gadget))
NBSongs = CountGadgetItems(#ListFile_Gadget)
SetGadgetItemText(#ListFile_Gadget,-1,""+NBSongs+" tracks have been found in the Directory "+GetPathPart(GetGadgetText(#ListFile_Gadget)))
EndIf
Case #ListFile_Gadget
If GetGadgetState(#Single_Gadget) = #True
If EventType() = #PB_EventType_LeftClick
File$ = GetGadgetText(#ListFile_Gadget)+GetGadgetItemText(#ListFile_Gadget, GetGadgetState(#ListFile_Gadget))
If File$ <> ""
loadSongRND(File$)
EndIf
EndIf
EndIf
Case #Pause_Button
If PauseAktiv= 1
PauseAktiv = 0
SetGadgetText(#Pause_Button,"Pause")
zplay_Play(hZPlay)
Else
PauseAktiv=1
SetGadgetText(#Pause_Button,"Play")
zplay_Pause(hZPlay)
EndIf
Case #Stop_Button
SetGadgetState(#Single_Gadget, 1)
zplay_Stop (hZplay)
zplay_Close(hZPlay)
Title_Text$ = "Please select Track"
Artist_Text$ = ""
Album_Text$ = ""
Year_Text$ = ""
Beschreibung = ""
Bit_Rate = 0
TotalTrackHour = 0
TotalTrackMin = 0
TotalTrackSec = 0
MaxTrackSec =0
biss$ = ""
File$ = ""
Case #Auto_Gadget
;
Case #Time_Gadget
;
Case #Exit_Button
Exit()
EndSelect
Case #PB_Event_CloseWindow
Exit()
EndSelect
ForEver
Procedure Exit()
Protected YesNo
YesNo = MessageRequester("Exit Program !", "Close Program ?"+#CRLF$+" "+#CRLF$+"PureBasic 5.60", #PB_MessageRequester_YesNo | #PB_MessageRequester_Info )
If YesNo = #PB_MessageRequester_Yes ; Ja-Button wurde gedrückt ? Dann Exit Programm !
End
EndIf
EndProcedure
Procedure.b onMouseOver(GadgedNr)
Protected X,Y,Mx,My
X = GadgetX(GadgedNr)
Y = GadgetY(GadgedNr)
Mx = WindowMouseX(#Open_Win)
My =WindowMouseY(#Open_Win)
If Mx > X And Mx < (X + GadgetWidth(GadgedNr)) And My > Y And My < (Y + GadgetHeight(GadgedNr) )
ProcedureReturn 1
EndIf
ProcedureReturn 0
EndProcedure
Procedure loadSongRND(File_RND$)
zplay_Stop(hZPlay)
If zplay_OpenFile(hZPlay,File_RND$, #sfAutodetect)
zplay_Play(hZPlay)
If zplay_GetStreamInfoW(hZPlay,@TSI)
TotalTrackMs=TSI\length.TStreamTime\hms.TStreamHMSTime\millisecond
TotalTrackSec=TSI\length.TStreamTime\hms.TStreamHMSTime\second
TotalTrackMin=TSI\length.TStreamTime\hms.TStreamHMSTime\minute
TotalTrackHour=TSI\length.TStreamTime\hms.TStreamHMSTime\hour
MaxTrackSec = TSI\length.TStreamTime\sec
EndIf
Indikator= TSI\vbr.l
Bit_Rate = TSI\Bitrate
Beschreibung = TSI\Description
If Indikator =#True
biss$ = "VBR"
Else
biss$= "CBR"
EndIf
If zplay_LoadID3W(hZPlay, #id3Version2, @ID3 )
Title_Text$ = ""+ id3\Title
Artist_Text$ = ""+ id3\Artist
Album_Text$ = ""+ id3\Album
Year_Text$ = ""+ id3\Year
EndIf
If Title_Text$ = #Empty$ : Title_Text$ = "Unknown ID3 TAG ":Else : Title_Text$ = ID3\Title : EndIf
If Artist_Text$ = #Empty$ : Artist_Text$ = "Please edit TAG " : Else : Artist_Text$ = ID3\Artist : EndIf
If Year_Text$ = #Empty$ : Year_Text$ = " " : Else : Year_Text$ = ID3\Year : EndIf
EndIf
EndProcedure
Procedure Start(now)
Repeat
If File$ >= ""
zplay_GetPosition(hZPlay,@TST)
zplay_GetStatus (hZplay,@TSS)
status = TSS\fplay
Trackpointsecond = TST\hms.TStreamHMSTime\second.l
Trackpointminute = TST\hms.TStreamHMSTime\minute.l
Trackpointhour = TST\hms.TStreamHMSTime\hour.l
PositionTrackPointsec = TST\Sec
PercentageValue = PositionTrackPointsec*100 / MaxTrackSec
If IsNAN(PercentageValue)
PercentageValue = 0
EndIf
listfile = GetGadgetState(#ListFile_Gadget)
If listfile = -1
listfile = 0
EndIf
zplay_GetStatus (hZplay,@TSS)
SetGadgetText(#String_Gadget_Titel,""+Space(5)+": "+Title_Text$)
SetGadgetText(#String_Gadget_Interpret,""+Space(5)+": "+Artist_Text$)
SetGadgetText(#String_Gadget_Album,""+Space(5)+": "+Album_Text$)
SetGadgetText(#String_Gadget_Year,""+Space(5)+": "+Year_Text$)
SetGadgetText(#String_Gadget_Format,""+Space(5)+": "+Beschreibung)
SetGadgetText(#String_Gadget_Bitrate,""+Space(5)+": "+Str(Bit_Rate)+Space(1)+"kbps"+Space(2)+biss$)
SetGadgetText(#String_Gadget_Total_Time,""+Space(5)+": "+RSet(Str(TotalTrackHour),2,"0")+":"+ RSet(Str(TotalTrackMin),2,"0")+":"+ RSet(Str(TotalTrackSec),2,"0"))
SetGadgetText(#String_Gadget_Real_Time,""+Space(5)+": "+RSet(Str(Trackpointhour),2,"0")+":"+ RSet(Str(Trackpointminute),2,"0")+":"+ RSet(Str(Trackpointsecond),2,"0"))
SetGadgetText(#String_Gadget_Percent,""+Space(5)+": "+StrF(PercentageValue,2)+ " %")
SetGadgetText(#String_Gadget_Play,""+Space(5)+": "+listfile+" from "+NBSongs)
SetGadgetState(#Progress_BarTime,Int(PercentageValue))
EndIf
Delay(500)
ForEver
EndProcedure
Procedure Level(Bel)
Repeat
zplay_DrawFFTGraphOnHWND(hZPlay, WindowID(#Open_Win),512,120,472,173)
If status = 1
zplay_GetVUData(hzplay,@links,@rechts)
Else
links = 0
rechts = 0
EndIf
SetGadgetState(#Progress_Left,links)
SetGadgetState(#Progress_Right,rechts)
Delay(80)
ForEver
EndProcedure