Jump to content
Sign in to follow this  
z0mgItsJohn

Simple Music Player v1.0

Recommended Posts

z0mgItsJohn

S.M.P. v1.0 - By : John O.

Features :

#1 Tray Mode

#2 Cool Song Add Function (Drag & Drop)

#3 Loop Song / Play All Options..

Screen-shots :

Posted ImagePosted Image

Source :

#Include <GUIConstantsEx.Au3>
#Include <WindowsConstants.Au3>
#Include <Misc.Au3>
#Include <Sound.Au3>
#Include <File.Au3>
#Include <String.Au3>
#Include <GUIListBox.Au3>
Opt ('GUIOnEventMode','1')
Opt ('TrayMenuMode','1')
Opt ('TrayOnEventMode','1') 
$SOptions = TrayCreateMenu ('Song Options')
$TPlay_S = TrayCreateItem ('Play Song', $SOptions)
TrayItemSetOnEvent ($TPlay_S, '_Play')
$TStop_S = TrayCreateItem ('Stop Song', $SOptions)
TrayItemSetOnEvent ($TStop_S, '_End')
$TPause_S = TrayCreateItem ('Pause Song', $SOptions)
TrayItemSetOnEvent ($TPause_S, '_Pause')
$TPAll_S = TrayCreateItem ('Play All', $SOptions)
TrayItemSetOnEvent ($TPAll_S, '_Play_All')
$TLoop_S = TrayCreateItem ('Loop Song', $SOptions) 
TrayItemSetOnEvent ($TLoop_S, '_Loop')
$POptions = TrayCreateMenu ('Program Options')
$PHide = TrayCreateItem ('Hide / Show', $POptions)
TrayItemSetOnEvent ($PHide, '_HideShow')
$PExit = TrayCreateItem ('Exit', $POptions)
TrayItemSetOnEvent ($PExit, '_Exit')

Global $S_Pause = False, $Open = '-1', $Toggle = False, $S_Play = False, $Time_S = '-1', $P_All = False, $L = 0, $Pos, $Length, $Loop = False, $1 = False
Global $Toggle = False, $Last = '-1'

$GUI = GUICreate ('S.M.P. v1.0 - By : John O.','300','236','-1','-1','-1','128')
GUISetBkColor ('0x000000')
GUISetOnEvent ($GUI_EVENT_CLOSE, '_Exit')
GUICtrlCreateGroup ('','5','0','289','32')
$Slider = GUICtrlCreateSlider ('8','9','283','20', BitOr ('0x0008','0x0010'))
GUICtrlSetOnEvent ($Slider, '_Seek')
GUICtrlSetBkColor ($Slider, '0')
GUICtrlCreateGroup ('','5','32','180','198')
$List = GUICtrlCreateList ('- No Songs -','8','41','174','200', BitOr ('0x00100000','0x1000','0xA00003'))
GUICtrlSetFont ($List, '9','600')
GUICtrlSetColor ($List, '0x0000FF')
GUICtrlCreateGroup ('','191','32','103','198')
$Add = GUICtrlCreateButton ('Add Song','194','41','97','20','32896')
GUICtrlSetOnEvent ($Add, '_Add_GUI')
GUICtrlSetBkColor ($Add, '0x000000')
GUICtrlSetColor ($Add, '0xFFFFFF')
GUICtrlSetFont ($Add, '9','600')
$Delete = GUICtrlCreateButton ('Delete Song','194','62','97','20','32896')
GUICtrlSetOnEvent ($Delete, '_Delete')
GUICtrlSetBkColor ($Delete, '0x000000')
GUICtrlSetColor ($Delete, '0xFFFFFF')
GUICtrlSetFont ($Delete, '9','600')
$Play = GUICtrlCreateButton ('Play Song','194','83','97','20','32896')
GUICtrlSetOnEvent ($Play, '_Play')
GUICtrlSetBkColor ($Play, '0x000000')
GUICtrlSetColor ($Play, '0xFFFFFF')
GUICtrlSetFont ($Play, '9','600')
$Stop = GUICtrlCreateButton ('Stop Song','194','104','97','20','32896')
GUICtrlSetOnEvent ($Stop, '_End')
GUICtrlSetBkColor ($Stop, '0x000000')
GUICtrlSetColor ($Stop, '0xFFFFFF')
GUICtrlSetFont ($Stop, '9','600')
$Pause = GUICtrlCreateButton ('Pause Song','194','125','97','20','32896')
GUICtrlSetOnEvent ($Pause, '_Pause')
GUICtrlSetBkColor ($Pause, '0x000000')
GUICtrlSetColor ($Pause, '0xFFFFFF')
GUICtrlSetFont ($Pause, '9','600')
$Play_All = GUICtrlCreateButton ('Play All','194','146','97','20','32896')
GUICtrlSetOnEvent ($Play_All, '_Play_All')
GUICtrlSetBkColor ($Play_All, '0x000000')
GUICtrlSetColor ($Play_All, '0xFFFFFF')
GUICtrlSetFont ($Play_All, '9','600')
$Loop_Song = GUICtrlCreateButton ('Loop Song','194','167','97','20','32896')
GUICtrlSetOnEvent ($Loop_Song, '_Loop')
GUICtrlSetBkColor ($Loop_Song, '0x000000')
GUICtrlSetColor ($Loop_Song, '0xFFFFFF')
GUICtrlSetFont ($Loop_Song, '9','600')
$L_Pos = GUICtrlCreateLabel ('00:00:00','213','192','100','20')
GUICtrlSetColor ('-1','0xFF0000')
GUICtrlSetBkColor ('-1', $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetFont ('-1','9','600','','Arial')
GUICtrlCreateLabel ('___________','209','195','100','13')
GUICtrlSetColor ('-1','0xFFFFFF')
GUICtrlSetBkColor ('-1', $GUI_BKCOLOR_TRANSPARENT)
$L_Length = GUICtrlCreateLabel ('00:00:00','213','208','100','20')
GUICtrlSetColor ('-1','0xFF0000')
GUICtrlSetBkColor ('-1', $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetFont ('-1','9','600','','Arial')
GUISetState (@SW_SHOW, $GUI)
WinSetOnTop ($GUI, '','1')
_List ()

While '1'
Sleep ('10') 
If $Toggle <> False Then 
$Pos = _SoundPos ($Open, '2')
$Length = _SoundLength ($Open, '2')
_Update (_SoundPos ($Open), _SoundLength ($Open))
If $Pos >= $Length Then _End ()
$X = $Pos / $Length * '100'
If _Check () == '0' Then GUICtrlSetData ($Slider, $X)
EndIf 
WEnd

Func _Play ()
If $S_Play = True And $S_Pause = False Then Return @Error 
If $P_All = True Then 
$Song = FileReadLine ('List.ini', $L)
If $Song = '-1' Then Return @Error 
$Open = _SoundOpen ($Song)
_SoundPlay ($Open)
$Toggle = True 
$S_Play = True 
Return '1'
EndIf 
If $S_Pause = True Then 
$S_Pause = False
_SoundResume ($Open)
Else 
If FileExists ('List.ini') = '0' Then Return @Error 
If GUICtrlRead ($List) = '' Then Return @Error 
$Song = _GetCurrentSong ()
If $Song = '-1' Then Return @Error 
$Open = _SoundOpen ($Song)
_SoundPlay ($Open)
$Toggle = True 
$S_Play = True 
EndIf 
EndFunc

Func _Convert ($Mili_Sec)
Local $Hour = '0', $Min = '0', $Sec = '0', $R['4']
$Sec = $Mili_Sec / '1000'
If $Sec > '60' Then 
Do 
$Sec = $Sec - '60'
$Min = $Min + '1'
Until $Sec < '60'
EndIf 
If $Min > '60' Then 
Do 
$Min = $Min - '60'
$Hour = $Hour + '1'
Until $Min < '60'
EndIf 
Dim $R 
$R['1'] = $Hour
$R['2'] = $Min
$R['3'] = $Sec
Return $R
EndFunc

Func _Update ($S_Pos, $S_Length)
If $Last <> '-1' And TimerDiff ($Last) < '800' Then Return @Error 
GUICtrlSetData ($L_Pos, $S_Pos)
If GUICtrlRead ($L_Length) <> $S_Length Then GUICtrlSetData ($L_Length, $S_Length)
$Last = TimerInit ()
EndFunc

Func _Check ()
Local $Aa = '0'
If _IsPressed ('01') Or _IsPressed ('25') Or _IsPressed ('27') Then $Aa = '1'
If ControlGetFocus ($GUI) = 'msctls_trackbar321' And $Aa = '1' Then $Time_S = TimerInit ()
If $Time_S <> '-1' And TimerDiff ($Time_S) >= '1000' Then 
$Time_S = '-1'
ElseIf $Time_S <> '-1' Then  
Return '1'
EndIf 
If ControlGetFocus ($GUI) = 'msctls_trackbar321' And $Aa = '1' Then
$Time_S = TimerInit ()  
Return '1'
Else 
Return '0'
EndIf 
EndFunc

Func _Add_GUI ()
WinSetOnTop ($GUI, '','0')
Global $GUI_Add = GUICreate ('Drag-&-Drop 2 Add Files','200','100','-1','-1','-1', BitOr ('128','0x00000010'))
GUISetBkColor ('0x000000')
GUISetOnEvent ($GUI_EVENT_CLOSE, '_Exit_Add')
GUISetOnEvent ($GUI_EVENT_DROPPED, '_Add')
Global $Edit = GUICtrlCreateEdit ('','0','0','200','100','3')
GUICtrlSetState ('-1', BitOr ($GUI_DISABLE, $GUI_DROPACCEPTED))
GUICtrlSetBkColor ('-1','0x000000')
GUICtrlSetColor ('-1','0x000000')
GUISetState (@SW_SHOW, $GUI_Add)
WinSetOnTop ($GUI_Add, '','1')
EndFunc

Func _Exit ()
Exit
EndFunc

Func _Loop ()
If FileExists ('List.ini') = '0' Then Return @Error 
If $P_All = True Then Return @Error 
If GUICtrlRead ($List) = '' Then Return @Error 
If $Loop = False Then 
If $S_Play = False Then _Play ()
GUICtrlSetData ($Loop_Song, 'Stop Loop')
TrayItemSetText ($TLoop_S, 'Stop Loop')
GUICtrlSetState ($Stop, $GUI_DISABLE)
TrayItemSetState ($TStop_S, '128')
$Loop = True 
Else
GUICtrlSetData ($Loop_Song, 'Loop Song')
TrayItemSetText ($TLoop_S, 'Loop Song')
GUICtrlSetState ($Stop, $GUI_ENABLE)
TrayItemSetState ($TStop_S, '64')
$Loop = False
EndIf 
EndFunc

Func _Add ()
GUICtrlSetData ($Edit, '')
FileWriteLine ('List.ini', @GUI_DragFile)
_List ()
EndFunc

Func _List ()
Local $Data, $C
If FileExists ('List.ini') = '1' Then 
$Count = _FileCountLines ('List.ini')
For $A = '1' To $Count
$Read = FileReadLine ('List.ini', $A)
$Read = StringSplit ($Read, '\')
$Read = _FileGetName ($Read[$Read['0']])
If $A < '10' Then 
$C = '0' & $A 
Else 
$C = $A 
EndIf 
$Data = $Data & '#' & $C & '.) ' & $Read & '|'
Next
$Data = StringTrimRight ($Data, '1')
GUICtrlSetData ($List, '')
GUICtrlSetData ($List, $Data)
_GUICtrlListBox_UpdateHScroll ($List)
EndIf 
EndFunc

Func _FileGetName ($iFile)
$Char = StringSplit (_FileGetType ($iFile), '')
$Char = $Char['0']
Return StringTrimRight ($iFile, $Char)
EndFunc

Func _FileGetType ($iFile)
$String = _StringReverse ($iFile)
$String = StringSplit ($String, '.')
$String = '.' & _StringReverse ($String['1'])
Return $String
EndFunc

Func _Delete ()
If FileExists ('List.ini') = '0' Then Return @Error 
$Read = GUICtrlRead ($List)
If $Read = '' Then Return @Error 
$Read = StringSplit ($Read, ')')
$Line = StringReplace (StringReplace ($Read['1'], '#',''), '.','')
If StringLeft ($Line, '1') = '0' Then $Line = StringTrimLeft ($Line, '1')
WinSetOnTop ($GUI, '','0')
$Msg = MsgBox ('4','Delete?','Are you sure you want to delete song #' & $Line & '?')
WinSetOnTop ($GUI, '','1')
If $Msg == '6' Then _Remove_Line ($Line)
If $Msg == '6' And $P_All = True Then $L = $L - 1
If $Msg == '6' Then _End ()
EndFunc

Func _Play_All ()
If $Loop = True Then Return @Error 
If FileExists ('List.ini') = '0' Then Return @Error 
If $P_All = False Then 
GUICtrlSetData ($Play_All, 'Stop All')
TrayItemSetText ($TPAll_S, 'Stop All')
GUICtrlSetData ($Stop, 'Next Song')
TrayItemSetText ($TStop_S, 'Next Song')
$P_All = True
$L = 1
_GUICtrlListBox_SetCurSel ($List, 0)
_Play ()
Else 
GUICtrlSetData ($Play_All, 'Play All')
TrayItemSetText ($TPAll_S, 'Play All')
GUICtrlSetData ($Stop, 'Stop Song')
TrayItemSetText ($TStop_S, 'Stop Song')
$P_All = False
$L = 0
GUICtrlSetData ($Slider, '0')
_GUICtrlListBox_SetCurSel ($List, $L - 1)
_End ()
EndIf 
EndFunc

Func _GetCurrentSong ()
$Split = StringSplit (GUICtrlRead ($List), ')')
$Split = StringReplace (StringReplace ($Split['1'], '#',''),'.','')
If StringLeft ($Split, '1') = '0' Then $Split = StringTrimLeft ($Split, '1')
Return FileReadLine ('List.ini', $Split)
EndFunc

Func _Remove_Line ($iLine)
Local $Temp = @TempDir & '\Temp.txt'
$Count = _FileCountLines ('List.ini')
If $Count = '1' And $iLine = '1' Then 
FileDelete ('List.ini')
GUICtrlSetData ($List, '')
GUICtrlSetData ($List, '- No Songs -')
Return @Error 
EndIf 
For $A = '1' To $Count
If $A <> $iLine Then FileWriteLine ($Temp, FileReadLine ('List.ini', $A))
Next
FileCopy ($Temp, @ScriptDir & '\List.ini', '1')
FileDelete ($Temp)
_List ()
EndFunc

Func _End ()
If GUICtrlRead ($List) = '' Then Return @Error 
If $L = _FileCountLines ('List.ini') Then _Play_All ()
If $Toggle = False Then Return @Error 
If $S_Play = False Then Return @Error 
_SoundStop ($Open)
_SoundClose ($Open)
$S_Pause = False
$Open = '-1'
$Toggle = False
$S_Play = False
$Pos = '0'
$Length = '1'
$Last = '-1'
_Update ('00:00:00','00:00:00')
GUICtrlSetData ($Slider, '0')
If $Loop = True Then _Play ()
If $P_All = True Then 
$L = $L + 1
_GUICtrlListBox_SetCurSel ($List, $L - 1)
_Play ()
EndIf 
EndFunc

Func _Pause ()
If $Toggle = False Then Return @Error 
If $S_Play = False Then Return @Error 
If $S_Pause = True Then Return @Error 
$S_Pause = True 
_SoundPause ($Open)
EndFunc 

Func _Seek ()
If $Toggle = False Then Return @Error 
If $S_Play = False Then Return @Error 
_SoundStop ($Open)
$S = GUICtrlRead ($Slider)
If $S = '100' Then _End ()
$P = (_SoundLength ($Open, '2') / '100') * $S 
$P = _Convert ($P)
_SoundSeek ($Open, Round ($P['1'], '0'), Round ($P['2'], '0'), Round ($P['3'], '0'))
_SoundPlay ($Open)
EndFunc

Func _HideShow ()
If $Toggle = False Then 
$Toggle = True 
WinSetState ($GUI, '', @SW_HIDE)
Else 
$Toggle =False
WinSetState ($GUI, '', @SW_SHOW)
EndIf 
EndFunc

Func _Exit_Add ()
WinSetOnTop ($GUI_Add, '','0')
GUIDelete ($GUI_Add)
WinSetOnTop ($GUI, '','1')
EndFunc

Download : [Click Here] *Includes Compiled Version

Well I hope this helps people out :D !

- John :D


Latest Projects :- New & Improved TCP Chat

Share this post


Link to post
Share on other sites
mesale0077

hi

nice code but always top onthe desktop ,

can you add volume control button?,add try mode

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×