Opt("MustDeclareVars", 1)
Opt("TrayMenuMode", 1)
Opt("TrayAutoPause", 0)
Opt("TrayOnEventMode", 1)
Opt("GUIOnEventMode", 1)
AutoItWinSetTitle("Media Player Minimal")
TraySetToolTip("Media Player Minimal")
;~ TraySetIcon(@ScriptFullPath, "AAICON")
TraySetIcon(@ScriptDir & '\IconRes\AAICON.ICO', 0)
TraySetState(2)
Global $Trayshow = TrayCreateItem("H&iện")
TrayCreateItem("")
Global $Trayplay = TrayCreateItem("C&hơi")
Global $Traypause = TrayCreateItem("Tạm dừng")
Global $Traystop = TrayCreateItem("&Dừng")
Global $Trayback = TrayCreateItem("&Trước")
Global $Traynext = TrayCreateItem("&Tiếp")
TrayCreateItem("")
Global $Trayopen = TrayCreateItem("&Mở")
TrayCreateItem("")
Global $Trayabout = TrayCreateItem("&Info")
Global $Trayexit = TrayCreateItem("&Thoát")
TrayItemSetState($Trayshow, 580)
TrayItemSetState($Trayplay, 132)
TrayItemSetState($Traypause, 132)
TrayItemSetState($Traystop, 132)
TrayItemSetState($Trayback, 132)
TrayItemSetState($Traynext, 132)
TrayItemSetOnEvent($Trayshow, "_ShowGUI")
TrayItemSetOnEvent($Trayplay, "_Play")
TrayItemSetOnEvent($Traypause, "_Pause")
TrayItemSetOnEvent($Traystop, "_Stop")
TrayItemSetOnEvent($Trayopen, "_Open")
TrayItemSetOnEvent($Trayabout, "_TrayAbout")
TrayItemSetOnEvent($Trayexit, "_Exit")
Global $File, $Sound, $Drag = False, $x, $y
Global $Gui = GUICreate("Máy nghe nhạc", 160, 50, (@DesktopWidth - 160) / 2, 5, 0x80880000,0x88)
Global $Pos = GUICtrlCreateSlider(0, 15, 160, 20, 0x38)
;~ Global $Open = GUICtrlCreateIcon(@ScriptFullPath, "AAICON", 5, 0, 16, 16)
;~ Global $Play = GUICtrlCreateIcon(@ScriptFullPath, "PLAY", 4, 34, 16, 16)
;~ Global $Pause = GUICtrlCreateIcon(@ScriptFullPath, "PAUSE", 20, 34, 16, 16)
;~ Global $Stop = GUICtrlCreateIcon(@ScriptFullPath, "STOP", 36, 34, 16, 16)
;~ Global $About = GUICtrlCreateIcon(@ScriptFullPath, "ABOUT", 108, 0, 16, 16)
;~ Global $Tray = GUICtrlCreateIcon(@ScriptFullPath, "TRAY", 124, 0, 16, 16)
;~ Global $Move = GUICtrlCreateIcon(@ScriptFullPath, "MOVE", 94, 0, 16, 16)
;~ Global $Close = GUICtrlCreateIcon(@ScriptFullPath, "CLOSE", 140, 0, 16, 16)
Global $Open = GUICtrlCreateIcon("IconRes\AAICON.ICO", 0, 5, 0, 16, 16)
Global $Play = GUICtrlCreateIcon("IconRes\PLAY.ico", 0, 4, 34, 16, 16)
Global $Pause = GUICtrlCreateIcon("IconRes\PAUSE.ico", 0, 20, 34, 16, 16)
Global $Stop = GUICtrlCreateIcon("IconRes\STOP.ico", 0, 36, 34, 16, 16)
Global $About = GUICtrlCreateIcon("IconRes\ABOUT.ico", 0, 108, 0, 16, 16)
Global $Tray = GUICtrlCreateIcon("IconRes\TRAY.ico", 0, 124, 0, 16, 16)
Global $Move = GUICtrlCreateIcon("IconRes\MOVE.ico", 0, 94, 0, 16, 16)
Global $Close = GUICtrlCreateIcon("IconRes\CLOSE.ico", 0, 140, 0, 16, 16)
GUICtrlSetLimit($Pos, 0, 0)
GUICtrlSetData($Pos, 0)
GUICtrlSetState($Pos, 128)
GUICtrlSetTip($Pos, "Position")
GUICtrlSetTip($Play, "Chơi")
GUICtrlSetState($Play, 128)
GUICtrlSetState($Pause, 128)
GUICtrlSetTip($Pause, "Dừng")
GUICtrlSetState($Stop, 128)
GUICtrlSetTip($Stop, "Dừng hẳn")
GUICtrlSetTip($Open, "Mở")
GUICtrlSetTip($Move, "Di chuyển")
GUICtrlSetTip($Close, "Đóng")
GUICtrlSetTip($Tray, "Thu nhỏ xuống")
GUICtrlSetTip($About, "Được viết bởi Nguyễn Vũ Trường Giang" & @CRLF & "Email :
nguyenvutruongg@yahoo.com.vn", "Thông tin về phần mềm", 1, 3)
GUICtrlSetOnEvent($Play, "_Play")
GUICtrlSetOnEvent($Pause, "_Pause")
GUICtrlSetOnEvent($Stop, "_Stop")
GUICtrlSetOnEvent($Open, "_Open")
GUICtrlSetOnEvent($Close, "_Exit")
GUICtrlSetOnEvent($Tray, "_HideGUI")
GUICtrlSetOnEvent($Move, "_Move")
GUISetOnEvent(-3, "_Exit", $Gui)
GUISetState(@SW_SHOW, $Gui)
GUIRegisterMsg(0x0114, "_Seek")
While 1
If __Sound_Length($Sound) = __Sound_Pos($Sound) Then _Play()
GUICtrlSetData($Pos, __Sound_Pos($Sound) / 1000)
Sleep(100)
WEnd
; ----------------------------------------------------------------------------------------------------
Func _Drag()
WinMove("Media Player Minimal", "", MouseGetPos(0) - $x, MouseGetPos(1) - $y)
EndFunc ;==>_Drag
; ----------------------------------------------------------------------------------------------------
Func _Exit()
TrayItemSetState($Trayexit, 68)
__Sound_Close($Sound)
GUIDelete($Gui)
Exit
EndFunc ;==>_Exit
; ----------------------------------------------------------------------------------------------------
Func _GetMousePos($fToClient = False, $hWnd = 0)
Local $iMode = Opt("MouseCoordMode", 1)
Local $aPos = MouseGetPos()
Opt("MouseCoordMode", $iMode)
Local $tPoint = DllStructCreate("int X;int Y")
DllStructSetData($tPoint, "X", $aPos[0])
DllStructSetData($tPoint, "Y", $aPos[1])
If $fToClient Then
_ScreenToClient($hWnd, $tPoint)
If @error Then Return SetError(@error, @extended, 0)
EndIf
Return $tPoint
EndFunc ;==>_GetMousePos
; ----------------------------------------------------------------------------------------------------
Func _GetMousePosX($fToClient = False, $hWnd = 0)
Local $tPoint = _GetMousePos($fToClient, $hWnd)
If @error Then Return SetError(@error, @extended, 0)
Return DllStructGetData($tPoint, "X")
EndFunc ;==>_GetMousePosX
; ----------------------------------------------------------------------------------------------------
Func _GetMousePosY($fToClient = False, $hWnd = 0)
Local $tPoint = _GetMousePos($fToClient, $hWnd)
If @error Then Return SetError(@error, @extended, 0)
Return DllStructGetData($tPoint, "Y")
EndFunc ;==>_GetMousePosY
; ----------------------------------------------------------------------------------------------------
Func _HideGUI()
GUISetState(@SW_HIDE, $Gui)
TraySetState(1)
EndFunc ;==>_HideGUI
; ----------------------------------------------------------------------------------------------------
Func _Move()
$Drag = Not $Drag
If $Drag = True Then
$x = _GetMousePosX(True, $Gui)
$y = _GetMousePosY(True, $Gui)
AdlibRegister("_Drag", 20)
Else
AdlibUnRegister("_Drag")
EndIf
EndFunc ;==>_Move
; ----------------------------------------------------------------------------------------------------
Func _Pause()
__Sound_Pause($Sound)
TrayItemSetState($Trayplay, 68)
TrayItemSetState($Traypause, 132)
TrayItemSetState($Traystop, 132)
GUICtrlSetState($Pos, 128)
GUICtrlSetState($Pause, 128)
GUICtrlSetState($Stop, 128)
GUICtrlSetState($Play, 64)
EndFunc ;==>_Pause
; ----------------------------------------------------------------------------------------------------
Func _Play()
GUICtrlSetData($Pos, 0)
GUICtrlSetLimit($Pos, __Sound_Length($Sound) / 1000, 0)
__Sound_Play($Sound)
TrayItemSetState($Trayplay, 132)
TrayItemSetState($Traypause, 68)
TrayItemSetState($Traystop, 68)
;~ TrayItemSetState($Trayopen, 132)
GUICtrlSetState($Pos, 64)
GUICtrlSetState($Play, 128)
GUICtrlSetState($Pause, 64)
GUICtrlSetState($Stop, 64)
;~ GUICtrlSetState($Open, 128)
EndFunc ;==>_Play
; ----------------------------------------------------------------------------------------------------
Func _ScreenToClient($hWnd, ByRef $tPoint)
Local $aResult = DllCall("user32.dll", "bool", "ScreenToClient", "hwnd", $hWnd, "ptr", DllStructGetPtr($tPoint))
If @error Then Return SetError(@error, @extended, False)
Return $aResult[0]
EndFunc ;==>_ScreenToClient
; ----------------------------------------------------------------------------------------------------
Func _Seek($hWnd, $iMsg, $iwParam, $ilParam)
Local $spos = GUICtrlRead($Pos)
Local $h, $m, $s
$h = Floor($spos / 3600)
$m = Floor(($spos - $h * 60) / 60)
$s = $spos - $h * 3600 - $m * 60
__Sound_Seek($Sound, 0, 0, $spos)
__Sound_Play($Sound)
EndFunc ;==>_Seek
; ----------------------------------------------------------------------------------------------------
Func _ShowGUI()
TrayItemSetState($Trayshow, 580)
GUISetState(@SW_SHOW, $Gui)
TraySetState(2)
EndFunc ;==>_ShowGUI
; ----------------------------------------------------------------------------------------------------
Func _Stop()
__Sound_Stop($Sound)
TrayItemSetState($Trayplay, 68)
TrayItemSetState($Traypause, 132)
TrayItemSetState($Traystop, 132)
;~ TrayItemSetState($Trayopen, 68)
GUICtrlSetState($Pos, 128)
GUICtrlSetState($Pause, 128)
GUICtrlSetState($Stop, 128)
GUICtrlSetState($Play, 64)
;~ GUICtrlSetState($Open, 64)
GUICtrlSetLimit($Pos, 0, 0)
GUICtrlSetData($Pos, 0)
EndFunc ;==>_Stop
; ----------------------------------------------------------------------------------------------------
Func _TrayAbout()
TrayItemSetState($Trayabout, 68)
TrayTip("About Media Player Minimal", "Được viết bởi Nguyễn Vũ Trường Giang" & @CRLF & "Email :
nguyenvutruongg@yahoo.com.vn", 5, 1)
EndFunc ;==>_TrayAbout
; ----------------------------------------------------------------------------------------------------
Func _Open()
TrayItemSetState($Trayopen, 68)
GUICtrlSetState($Play, 64)
GUISetState(@SW_DISABLE, $Gui)
__Sound_Close($Sound)
$File = FileOpenDialog("Mở", @MyDocumentsDir & "/", "Tất cả các file âm thanh (*.mp3; *.wav; *.wma; *.mid; *.mdi; *.midi; *.rmi)| MPEG Layer 3 Audio File (*.mp3)| WAVE Audo File (*.wav)| Windows Media Audio File (*.wma)| MIDI File (*.mid; *.mdi; *.midi; *.rmi)|Tất cả các file (*.*)", 3, "Tên file :GiangPro")
If Not @error Then
$Sound = __Sound_Open($File)
If @error Then
MsgBox(0, "Lỗi", "Không thể mở file!")
Else
_Play()
EndIf
EndIf
GUISetState(@SW_ENABLE, $Gui)
EndFunc ;==>_Open
; ----------------------------------------------------------------------------------------------------
Func __Sound_Open($sFile)
Local $aSndID
For $i = 1 To 10
$aSndID &= Chr(Random(97, 122, 1))
Next
___Sound_MciSendString("open " & FileGetShortName($sFile) & " alias " & $aSndID)
If @error Then Return SetError(1, @error, 0)
Return $aSndID
EndFunc ;==>__Sound_Open
; ----------------------------------------------------------------------------------------------------
Func __Sound_Close($aSndID)
___Sound_MciSendString("close " & $aSndID)
If @error Then Return SetError(1, @error, 0)
Return 1
EndFunc ;==>__Sound_Close
; ----------------------------------------------------------------------------------------------------
Func __Sound_Play($aSndID)
If __Sound_Pos($aSndID) = __Sound_Length($aSndID) Then ___Sound_MciSendString("seek " & $aSndID & " to start")
___Sound_MciSendString("play " & $aSndID)
If @error Then Return SetError(1, @error, 0)
Return 1
EndFunc ;==>__Sound_Play
; ----------------------------------------------------------------------------------------------------
Func __Sound_Stop(ByRef $aSndID)
___Sound_MciSendString("stop " & $aSndID)
If @error Then Return SetError(2, @error, 0)
___Sound_MciSendString("seek " & $aSndID & " to start")
If @error Then Return SetError(1, @error, 0)
Return 1
EndFunc ;==>__Sound_Stop
; ----------------------------------------------------------------------------------------------------
Func __Sound_Pause($aSndID)
___Sound_MciSendString("pause " & $aSndID)
If @error Then Return SetError(1, @error, 0)
Return 1
EndFunc ;==>__Sound_Pause
; ----------------------------------------------------------------------------------------------------
Func __Sound_Length($aSndID)
___Sound_MciSendString("set " & $aSndID & " time format miliseconds")
Return Number(___Sound_MciSendString("status " & $aSndID & " length", 255))
EndFunc ;==>__Sound_Length
; ----------------------------------------------------------------------------------------------------
Func __Sound_Seek(ByRef $aSndID, $iHour, $iMin, $iSec)
___Sound_MciSendString("set " & $aSndID & " time format miliseconds")
Local $iMs = $iSec * 1000
$iMs += $iMin * 60 * 1000
$iMs += $iHour * 60 * 60 * 1000
___Sound_MciSendString("seek " & $aSndID & " to " & $iMs)
If @error Then Return SetError(1, @error, 0)
Return 1
EndFunc ;==>__Sound_Seek
; ----------------------------------------------------------------------------------------------------
Func __Sound_Pos($aSndID)
___Sound_MciSendString("set " & $aSndID & " time format miliseconds")
Return Number(___Sound_MciSendString("status " & $aSndID & " position", 255))
EndFunc ;==>__Sound_Pos
; ----------------------------------------------------------------------------------------------------
Func ___Sound_MciSendString($string, $iLen = 0)
Local $iRet = DllCall("winmm.dll", "dword", "mciSendStringW", "wstr", $string, "wstr", "", "uint", $iLen, "ptr", 0)
If @error Then Return SetError(@error, @extended, "")
If $iRet[0] Then Return SetError(10, $iRet[0], $iRet[2])
Return $iRet[2]
EndFunc ;==>___Sound_MciSendString