How can i play a random song?
How can i play a random song?
Hello,
How can i play a random song with the format mp3 from the specific folder "D:\1\Sounds1" and the Folder "D:\AllMusic\Music" ?
Thank you!
How can i play a random song with the format mp3 from the specific folder "D:\1\Sounds1" and the Folder "D:\AllMusic\Music" ?
Thank you!
Re: How can i play a random song?
Code: Select all
#SingleInstance Force
sound := []
For k, dir in ["D:\1\Sounds1", "D:\AllMusic\Music"]
Loop, Files, % dir "\*.mp3"
sound.Push(A_LoopFilePath)
If !sound.Count() {
MsgBox, 48, Error, No files were found. Aborting.
Return
} Else Random, rand, 1, sound.Count()
MsgBox,, Sound, % "Playing " sound[rand], 1
SoundPlay, % sound[rand], Wait
Re: How can i play a random song?
@mikeyww
Thank you!
How can i make the messagebox text bigger?
Thank you!
How can i make the messagebox text bigger?
Re: How can i play a random song?
Code: Select all
#SingleInstance Force
sound := []
For k, dir in ["D:\1\Sounds1", "D:\AllMusic\Music"]
Loop, Files, % dir "\*.mp3"
sound.Push(A_LoopFilePath)
If !sound.Count() {
MsgBox, 48, Error, No files were found. Aborting.
Return
} Else Random, rand, 1, sound.Count()
Gui, New
Gui, Font, s22 w500
Gui, Color, F8DC75
Gui, Add, Text, w320 Center, % sound[rand]
Gui, Show,, Now playing
SoundPlay, % sound[rand], Wait
Gui, Destroy
Re: How can i play a random song?
@mikeyww
Thank you!
How can i make the message box not appear in the middle, it should only appear in the taskbar. When i want to look what song it is i click manually at it on the taskbar.
So the message box can not interrupt other commands.
Thank you!
How can i make the message box not appear in the middle, it should only appear in the taskbar. When i want to look what song it is i click manually at it on the taskbar.
So the message box can not interrupt other commands.
Re: How can i play a random song?
@mikeyww
and how can i make it also play songs from the two folders subfolders?
and how can i make it also play songs from the two folders subfolders?
Re: How can i play a random song?
See Loop, Files. Use mode R.
Re: How can i play a random song?
@mikeyww
Thanks again for your help! Have a good day!
Thanks again for your help! Have a good day!
Re: How can i play a random song?
@mikeyww
How can i do this? :
when the music is already playing and i press the button again then it stops playing.
Thank you!
How can i do this? :
when the music is already playing and i press the button again then it stops playing.
Thank you!
Re: How can i play a random song?
Code: Select all
#SingleInstance Force
#MaxThreadsPerHotkey 2
sound := []
For k, dir in ["D:\1\Sounds1", "D:\AllMusic\Music"]
Loop, Files, % dir "\*.mp3", R
sound.Push(A_LoopFilePath)
F3::
If !sound.Count() {
MsgBox, 48, Error, No files were found. Aborting.
Return
}
If (on := !on) {
Random, rand, 1, sound.Count()
Gui, New
Gui, Font, s22 w500
Gui, Color, F8DC75
Gui, Add, Text, w320 Center, % sound[rand]
Gui, Show,, Now playing
SoundPlay, % sound[rand], Wait
}
Gui, Destroy
on := False
SoundPlay, ""
Return
Re: How can i play a random song?
@mikeyww
How can I play only mp3 files longer than 60 seconds?
Thank you!
How can I play only mp3 files longer than 60 seconds?
Thank you!
Re: How can i play a random song?
You got me on that one! I think you will probably want to read the MP3 metadata to determine the audio duration or length. You could search the forum for that. Command-line tools are also available to do it.
-
- Posts: 4309
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: How can i play a random song?
How to Find the Duration of a Media File
Code: Select all
filePath := "J:\_MUSIC_\Progressive Rock\Gordian Knot\1998 Gordian Knot\03.Reflections.mp3"
sec := GetMediaDuration(filePath)
min := sec//60
restSec := mod(sec, 60)
MsgBox, % min . " min " . restSec . " sec"
GetMediaDuration(mediaFilePath) {
static MF_VERSION := 0x2, MFSTARTUP_NOSOCKET := 0x1, MF_RESOLUTION_MEDIASOURCE := 1
, IID_IMFMediaSource := "{279A808D-AEC7-40C8-9C6B-A6B492C78A66}"
, MF_PD_DURATION := "{6c990d33-bb8e-477a-8598-0d5d96fcd88a}"
DllCall("Mfplat\MFStartup", "UInt", MF_VERSION, "UInt", MFSTARTUP_NOSOCKET, "UInt")
DllCall("Mfplat\MFCreateSourceResolver", "PtrP", pIMFSourceResolver)
; IMFSourceResolver::CreateObjectFromURL
DllCall(NumGet(NumGet(pIMFSourceResolver + 0) + A_PtrSize*3), "Ptr", pIMFSourceResolver, "WStr", mediaFilePath
, "UInt", MF_RESOLUTION_MEDIASOURCE, "Ptr", 0
, "UIntP", MF_OBJECT_TYPE, "PtrP", pIUnknown, "UInt")
pIMFMediaSource := ComObjQuery(pIUnknown, IID_IMFMediaSource)
ObjRelease(pIUnknown)
; IMFMediaSource::CreatePresentationDescriptor
DllCall(NumGet(NumGet(pIMFMediaSource + 0) + A_PtrSize*8), "Ptr", pIMFMediaSource, "PtrP", pIMFPresentationDescriptor, "UInt")
VarSetCapacity(CLSID, 16, 0)
DllCall("ole32\CLSIDFromString", "WStr", MF_PD_DURATION, "Ptr", &CLSID, "UInt")
; IMFPresentationDescriptor::GetUINT64
DllCall(NumGet(NumGet(pIMFPresentationDescriptor + 0) + A_PtrSize*8), "Ptr", pIMFPresentationDescriptor, "Ptr", &CLSID, "UInt64P", duration)
ObjRelease(pIMFPresentationDescriptor), ObjRelease(pIMFMediaSource), ObjRelease(pIMFSourceResolver)
DllCall("Mfplat\MFShutdown")
Return sec := duration//10**7
}
Re: How can i play a random song?
Awesome function to get Media Duration!
P.s.: try pIMFMediaSource := ComObjQuery(pIUnknown, IID_IMFMediaSource) seems to suffice for preventing error when Media file is corrupt.
P.s.: try pIMFMediaSource := ComObjQuery(pIUnknown, IID_IMFMediaSource) seems to suffice for preventing error when Media file is corrupt.
Spoiler
-
- Posts: 4309
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: How can i play a random song?
It's not necessarily corrupt, it can be not native for windows.