Play random mp3 in folder

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
jay lee
Posts: 83
Joined: 14 Oct 2021, 11:17

Play random mp3 in folder

14 Oct 2021, 11:35

hey, i want to make a musicplayer, and i don't know how to play random mp3 files in a folder successively with SoundPlay.
User avatar
Chunjee
Posts: 1419
Joined: 18 Apr 2014, 19:05
Contact:

Re: Play random mp3 in folder

14 Oct 2021, 12:34

If you put all your songpaths into an array; https://biga-ahk.github.io/biga.ahk/#/?id=sample can choose a random one

Code: Select all

A := new biga() ; requires https://www.npmjs.com/package/biga.ahk

; put all songs into an array
array := []
Loop, Files, % "C:/music/*.mp3"
{
	array.push(A_LoopFilePath)
}
; choose one file to play
file := A.sample(array)
SoundPlay, % file
return
User avatar
flyingDman
Posts: 2817
Joined: 29 Sep 2013, 19:01

Re: Play random mp3 in folder

14 Oct 2021, 13:49

try:

Code: Select all

path := "C:\Users\" A_UserName "\Music"
loop, files, %path%\*.mp3
	lst .= A_LoopFileFullPath "`n"
sort, lst, Random	
for x,y in strsplit(lst,"`n")
	soundplay, %y%, wait
14.3 & 1.3.7
jay lee
Posts: 83
Joined: 14 Oct 2021, 11:17

Re: Play random mp3 in folder

17 Oct 2021, 12:34

Thank you, this is working!!! :bravo:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Lamron750, nacken012 and 230 guests