Very well here is the full code. Again my problem is when i use CurrentMedia := AV2.newMedia( Song_Dir Song ) - AV2duration := CurrentMedia.getItemInfo( "duration" ) it returns in seconds i want to convert the seconds to minutes.
Code: Select all
#SingleInstance, Force
#Persistent
#KeyHistory 0
ListLines, off
SetBatchLines, -1
;-Variables---
Global PID := DllCall("GetCurrentProcessId")
Process, Priority, %PID%, RealTime
Global programName := "SongPlayer"
Global Song := "Enter Song To Play"
Global Song_Dir := "Set-Directory"
Global Musicformats := "wav,wma,mp3,mp4"
Global AV2 := ComObjCreate("WMPlayer.OCX")
Global SkipTo := "00.00"
Global PauseToggle := 0
Global f_Zip := "C:\SongPlayer\SongPlayer.zip" ; Zip file to be created
Global f_Unz := "C:\SongPlayer\" ; Directory to unzip files
;-------------
;---Start-----
CreateDirectory()
;-------------
;----TrayMenu----
Menu, Tray, NoStandard
Menu, Tray, Add, Reload, Reload
Menu, Tray, Add, Exit, Exit
;----------------
SetTimer, FindSong, 500
return
;--Functions-----
Gui()
{
Global
Gui 1: Color, c41057D
Gui 1: +Border
Gui 1: Margin,5,5
Gui 1: Font, s9, Comic Sans MS
Gui 1: Add, Picture, x0 y0 w600 h400, C:\SongPlayer\SongPlayerBG.png
Gui 1: Add, Edit, x25 y25 w550 h20 vSong +Center, %Song%
Gui 1: Add, Button, x25 y60 w60 h20 gSongPath +Center, Play
Gui 1: Add, Button, x95 y60 w60 h20 gButtonPause +Center, Pause
Gui 1: Add, Button, x95 y60 w60 h20 gButtonResume +Center +Hidden, Resume
Gui 1: Add, Button, x165 y60 w60 h20 gButtonStop +Center, Stop
Gui 1: Add, Button, x365 y60 w90 h20 gFastForward +Center, FastForward
Gui 1: Add, Button, x265 y60 w90 h20 gRewind +Center, Rewind
Gui 1: Font, Underline
Gui 1: Add, Text, c00FFFF x30 y94 gOpenSongDir +BackGroundTrans, Current Directory :>
Gui 1: Font, Norm
Gui 1: Add, Edit, w245 h20 x161 y90 vSong_Dir, %Song_Dir%\
Gui 1: Add, Button, w60 h20 x420 y90 gSetSongPlayerDirectoryButton, Set Dir
Gui 1: Font, norm s11
Gui 1: Add, Edit, c00FFFF x25 y180 w550 h210 ReadOnly +BackGroundTrans, Found Songs - %files%
Gui 1: Font, norm s9
Gui 1: Add, Button, w40 h20 x535 y60 gVolUp, Vol+
Gui 1: Add, Button, w40 h20 x485 y60 gVolDown, Vol-
Gui 1: Add, Text, c00FFFF x30 y137 +BackGroundTrans, Skip To Time :>
Gui 1: Add, Edit, w100 h20 x130 y135 vSkipTo, %SkipTo%
Gui 1: Add, Button, w60 h20 x240 y135 gSkipToTime, Skip To
Gui 1: Add, Text, c00FFFF x330 y135 +BackGroundTrans, Play Time :>
Gui 1: Add, Edit, c00FFFF x398 y134 w55 h20 vdisplay ReadOnly +Center, 00:00
Gui 1: Add, Text, c00FFFF x460 y135 +BackGroundTrans, Duration :>
Gui 1: Add, Edit, c00FFFF x525 y134 w45 h20 vdisplayV2 ReadOnly +Center, 00.00
Gui 1: Add, ActiveX, vAV, WMPLayer.OCX
Sleep 250
Gui 1: Show, w600 h400, SongPlayer
enableGuiDrag(1)
SetAppVolume(PID, 20)
}
SongPath()
{
Global
Gui 1: Submit, NoHide
Sleep 50
IfNotExist, %Song_Dir%\%Song%
{
tooltipN("!!Song Does NOT EXIST!!", mouseX, mouseY, 4000, 1)
}
else
{
Gui 1: Submit, NoHide
AV.Url := Song_Dir Song
if errorlevel = 1
{
tooltipN("!!Song NOT FOUND!!", mouseX, mouseY, 4000, 1)
}
else
{
tooltipN("Playing -- " Song, mouseX, mouseY, 4000, 1)
Menu, Tray, Tip, % "Playing -- " . Song
SongDuration()
SetTimer, SongTimeSub, 500
SetTimer, FindSong, 500 ; update every 500 milliseconds
}
}
}
ButtonPause()
{
Global
AV.controls.pause
If !ErrorLevel
{
GuiControl, Hide, Pause
GuiControl, Show, Resume
}
}
ButtonResume()
{
Global
AV.controls.play
If !ErrorLevel
{
GuiControl, Hide, Resume
GuiControl, Show, Pause
}
}
ButtonStop()
{
Global
AV.controls.Stop
SetTimer, FindSong, Off
}
FastForward()
{
Global
AV.Controls.currentPosition += 5
tooltipN("FastForward : 5 Seconds", mouseX, mouseY, 4000, 1)
}
Rewind()
{
Global
AV.Controls.currentPosition -= 5
tooltipN("Rewound : 5 Seconds", mouseX, mouseY, 4000, 1)
}
SkipToTime()
{
Global
Gui 1: Submit, Nohide
AV.Controls.currentPosition:= SkipTo * 60
}
FindSong()
{
Global
if AV.Controls.currentPosition = 0.00
{
Gui 1: Submit, Nohide
If FileExist(Song_dir Song)
{
SongDuration()
SongPath()
}
}
}
SongDuration()
{
Global
CurrentMedia := AV2.newMedia( Song_Dir Song )
AV2duration := CurrentMedia.getItemInfo( "duration" )
AV2duration /= 60
GuiControl,, displayV2, % format("{:0.2f}", AV2duration)
}
GetAppVolume(PID)
{
Local MasterVolume := ""
IMMDeviceEnumerator := ComObjCreate("{BCDE0395-E52F-467C-8E3D-C4579291692E}", "{A95664D2-9614-4F35-A746-DE8DB63617E6}")
DllCall(NumGet(NumGet(IMMDeviceEnumerator+0)+4*A_PtrSize), "UPtr", IMMDeviceEnumerator, "UInt", 0, "UInt", 1, "UPtrP", IMMDevice, "UInt")
ObjRelease(IMMDeviceEnumerator)
VarSetCapacity(GUID, 16)
DllCall("Ole32.dll\CLSIDFromString", "Str", "{77AA99A0-1BD6-484F-8BC7-2C654C9A9B6F}", "UPtr", &GUID)
DllCall(NumGet(NumGet(IMMDevice+0)+3*A_PtrSize), "UPtr", IMMDevice, "UPtr", &GUID, "UInt", 23, "UPtr", 0, "UPtrP", IAudioSessionManager2, "UInt")
ObjRelease(IMMDevice)
DllCall(NumGet(NumGet(IAudioSessionManager2+0)+5*A_PtrSize), "UPtr", IAudioSessionManager2, "UPtrP", IAudioSessionEnumerator, "UInt")
ObjRelease(IAudioSessionManager2)
DllCall(NumGet(NumGet(IAudioSessionEnumerator+0)+3*A_PtrSize), "UPtr", IAudioSessionEnumerator, "UIntP", SessionCount, "UInt")
Loop % SessionCount
{
DllCall(NumGet(NumGet(IAudioSessionEnumerator+0)+4*A_PtrSize), "UPtr", IAudioSessionEnumerator, "Int", A_Index-1, "UPtrP", IAudioSessionControl, "UInt")
IAudioSessionControl2 := ComObjQuery(IAudioSessionControl, "{BFB7FF88-7239-4FC9-8FA2-07C950BE9C6D}")
ObjRelease(IAudioSessionControl)
DllCall(NumGet(NumGet(IAudioSessionControl2+0)+14*A_PtrSize), "UPtr", IAudioSessionControl2, "UIntP", ProcessId, "UInt")
If (PID == ProcessId)
{
ISimpleAudioVolume := ComObjQuery(IAudioSessionControl2, "{87CE5498-68D6-44E5-9215-6DA47EF883D8}")
DllCall(NumGet(NumGet(ISimpleAudioVolume+0)+4*A_PtrSize), "UPtr", ISimpleAudioVolume, "FloatP", MasterVolume, "UInt")
ObjRelease(ISimpleAudioVolume)
}
ObjRelease(IAudioSessionControl2)
}
ObjRelease(IAudioSessionEnumerator)
Return Round(MasterVolume * 100)
}
SetAppVolume(pid, MasterVolume)
{
IMMDeviceEnumerator := ComObjCreate("{BCDE0395-E52F-467C-8E3D-C4579291692E}", "{A95664D2-9614-4F35-A746-DE8DB63617E6}")
DllCall(NumGet(NumGet(IMMDeviceEnumerator+0)+4*A_PtrSize), "UPtr", IMMDeviceEnumerator, "UInt", 0, "UInt", 1, "UPtrP", IMMDevice, "UInt")
ObjRelease(IMMDeviceEnumerator)
VarSetCapacity(GUID, 16)
DllCall("Ole32.dll\CLSIDFromString", "Str", "{77AA99A0-1BD6-484F-8BC7-2C654C9A9B6F}", "UPtr", &GUID)
DllCall(NumGet(NumGet(IMMDevice+0)+3*A_PtrSize), "UPtr", IMMDevice, "UPtr", &GUID, "UInt", 23, "UPtr", 0, "UPtrP", IAudioSessionManager2, "UInt")
ObjRelease(IMMDevice)
DllCall(NumGet(NumGet(IAudioSessionManager2+0)+5*A_PtrSize), "UPtr", IAudioSessionManager2, "UPtrP", IAudioSessionEnumerator, "UInt")
ObjRelease(IAudioSessionManager2)
DllCall(NumGet(NumGet(IAudioSessionEnumerator+0)+3*A_PtrSize), "UPtr", IAudioSessionEnumerator, "UIntP", SessionCount, "UInt")
Loop % SessionCount
{
DllCall(NumGet(NumGet(IAudioSessionEnumerator+0)+4*A_PtrSize), "UPtr", IAudioSessionEnumerator, "Int", A_Index-1, "UPtrP", IAudioSessionControl, "UInt")
IAudioSessionControl2 := ComObjQuery(IAudioSessionControl, "{BFB7FF88-7239-4FC9-8FA2-07C950BE9C6D}")
ObjRelease(IAudioSessionControl)
DllCall(NumGet(NumGet(IAudioSessionControl2+0)+14*A_PtrSize), "UPtr", IAudioSessionControl2, "UIntP", ProcessId, "UInt")
If (pid == ProcessId)
{
ISimpleAudioVolume := ComObjQuery(IAudioSessionControl2, "{87CE5498-68D6-44E5-9215-6DA47EF883D8}")
DllCall(NumGet(NumGet(ISimpleAudioVolume+0)+3*A_PtrSize), "UPtr", ISimpleAudioVolume, "Float", MasterVolume/100.0, "UPtr", 0, "UInt")
ObjRelease(ISimpleAudioVolume)
}
ObjRelease(IAudioSessionControl2)
}
ObjRelease(IAudioSessionEnumerator)
}
CreateDirectory()
{
Global
RegExMatch(A_ScriptName, "^(.*?)\.", basename)
if Not InStr(FileExist("C:\" basename1), "D") ; create appdata folder if doesnt exist
FileCreateDir , % "C:\" basename1
if !FileExist("C:\SongPlayer\SongPlayer.zip")
{
MsgBox,4100,, Files Required NOT Found!! Initiate Download?
IfMsgBox, Yes
{
Run, https anonfiles.com /z6hccbQco7/SongPlayer_zip Broken Link for safety
MsgBox,4096,,
(ltrim
Once downloaded just place zip file in C:\SongPlayer, on restart app will un-zip the files.
Press ok to restart
)
IfMsgBox, ok
{
Reload
Sleep 1000
}
else
{
ExitMessage()
}
}
else
{
ExitMessage()
}
}
if !FileExist("C:\SongPlayer\SongPlayerBG.png")
{
Unpack()
}
if FileExist("C:\SongPlayer\SongPlayerBG.png")
{
ReadSetSongDirIni()
SetSongPlayerDirectory()
doGetSongs()
StartMessage()
Gui()
}
}
ReadSetSongDirIni()
{
Global
if FileExist("C:\SongPlayer\SetSongPlayerDir.ini")
{
IniRead, Song_Dir, C:\SongPlayer\SetSongPlayerDir.ini, CurrentDirectory, Directory, %Song_Dir%
}
}
SetSongPlayerDirectory()
{
Global
if (Song_Dir = "Set-Directory")
{
FileSelectFolder, Song_Dir,,0, Select Your Music Directory
if ErrorLevel = 1
{
ExitMessage()
}
else
{
IniWrite, %Song_Dir%, C:\SongPlayer\SetSongPlayerDir.ini, CurrentDirectory, Directory
}
}
}
SetSongPlayerDirectoryButton()
{
Global
Gui 1: Submit, NoHide
tooltipN("Song Directory Set To : " Song_Dir, mouseX, mouseY, 1000, 1)
FileSelectFolder, Song_Dir,,0, Choose Music Directory
if ErrorLevel = 1
{
ExitApp
}
else
{
IniWrite, %Song_Dir%, C:\SongPlayer\SetSongPlayerDir.ini, CurrentDirectory, Directory
Reload
}
}
doGetSongs()
{
Global
Loop % Song_Dir . "\*.*",, 1
If (InStr(Musicformats,A_LoopFileExt) <> 0)
{
files = %files%`n%A_LoopFileName%
}
}
StartMessage()
{
Global
Menu, Tray, Icon, shell32.dll, 138
TrayTip, %programName%, Has Started!
}
ExitMessage()
{
Global
TrayTip, %programName%, Has Closed!
ExitApp
}
Unpack()
{
Unz(f_Zip, f_Unz)
Sleep, 500
}
Unz(sZip, sUnz)
{
psh := ComObjCreate("Shell.Application")
psh.Namespace( sUnz ).CopyHere( psh.Namespace( sZip ).items, 4|16 )
}
enableGuiDrag(GuiLabel=1)
{
WinGetPos,,,A_w,A_h,A
Gui, %GuiLabel%:Add, Text, x0 y0 w%A_w% h%A_h% +BackgroundTrans gGUI_Drag
return
GUI_Drag:
PostMessage 0xA1,2
return
}
ToolTipN(__tooltipText:="N/A", X := "", Y := "", __removeDelay:=0, __whichToolTip:=1)
{
static __n := 0
Tooltip % __tooltipText, % X, % Y, % __whichToolTip
__f := Func("removeToolTip").bind(__whichToolTip, ++__n) ; creates a function reference and binds it __whichToolTip which will be passed as argument for the callback function below
SetTimer, % __f, % -__removeDelay ; minus sign indicates settimer to run only once
return
}
removeToolTip(__whichToolTip, __n)
{
tooltip,,,, % __whichToolTip ; if tooltip text argument is empty the toottip is removed
}
PauseToggle()
{
Global
PauseToggle:=!PauseToggle
if PauseToggle = 1
{
PauseToggle = 1
ButtonPause()
}
else
{
PauseToggle = 0
ButtonResume()
}
}
FormatSeconds(NumberOfSeconds) ; Convert the specified number of seconds to hh:mm:ss format.
{
time = 19990101 ; *Midnight* of an arbitrary date.
time += %NumberOfSeconds%, seconds
FormatTime, mmss, %time%, mm:ss
return NumberOfSeconds//3600 ":" mmss
/*
; Unlike the method used above, this would not support more than 24 hours worth of seconds:
FormatTime, hmmss, %time%, h:mm:ss
return hmmss
*/
}
;---------------
;--Labels-------
VolUp:
SetAppVolume(PID, GetAppVolume(PID) + 5)
tooltipN("SongPlayer Volume : " GetAppVolume(PID), mouseX, mouseY, 4000, 1)
return
VolDown:
SetAppVolume(PID, GetAppVolume(PID) - 5)
tooltipN("SongPlayer Volume : " GetAppVolume(PID), mouseX, mouseY, 4000, 1)
return
OpenSongDir:
Run, %Song_Dir%
return
GuiClose:
ExitMessage()
return
Reload:
Reload
return
Exit:
ExitMessage()
return
RemoveToolTip:
ToolTip
return
SongTimeSub:
AV.Controls.currentPositionString
GuiControl,, display, % AV.Controls.currentPositionString
return
;----------------
;----HotKeys-----
~*^C::
KeyWait, C
KeyWait, C, D, T 0.10
if Errorlevel = 1
return
else
{
Sleep 50
GuiControl,, Song, % Clipboard
Gui 1: Submit, NoHide
}
return
~*Pause::
PauseToggle()
return
~*NumpadAdd::
SetAppVolume(PID, + 5)
return
~*NumpadSub::
SetAppVolume(PID, - 5)
return
;----------------