Jump to content

Looking for Script to play random Music files with random breakes


Recommended Posts

Hello,

i look for a script which plays a random music file from a folder, then make a break of a random time between 40 and 300 mins and then play another random file of the folder and so on.

Hope you can show me how to write this.

I want to learn it :)

Link to comment
Share on other sites

Try something like this here:

#include <Array.au3>
#include <File.au3>
#include <MsgBoxConstants.au3>

Global $sFolder = FileSelectFolder ("Select a folder with audio files", "")
If @error Then Exit MsgBox($MB_ICONERROR, "Error", "No folder was selected - exiting script!", 15)
Global $aFiles = _FileListToArrayRec($sFolder, "*.mp3", $FLTAR_FILES, $FLTAR_RECUR)
If @error Then Exit MsgBox($MB_ICONERROR, "Error", "No MP3 files were found!", 15)
If $aFiles[0] > 2 Then _ArrayShuffle($aFiles, 1)

OnAutoItExitRegister("_Exit")
HotKeySet("{ESC}", "_Exit")
Local $iPos = 1

Do
    SoundPlay($sFolder & "\" & $aFiles[$iPos], 1)
    $iPos += 1
    If $iPos > $aFiles[0] Then
        _ArrayShuffle($aFiles, 1)
        $iPos = 1
    EndIf
Until Not Sleep(Random(40 * 60 * 1000, 300 * 60 * 1000, 1))

Func _Exit()
    SoundPlay("")
    Exit
EndFunc

 

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

  • Moderators

@Ancrion welcome to AutoIt. The purpose of this forum is to assist people in improving their own scripts; it is not a place where you put in a request and someone generates code for you. I would suggest taking a look through the help file as a way to begin, you can look at SoundPlay if the music is a wav file or mp3. Something like this (pseudo-code) should get you started.

SoundPlay(<path to music file>) ;Play MP3
Sleep(10000) ;Wait 10 seconds
SoundPlay("") ;Call SoundPlay again to stop play

Once you get this going the way you would like, you can look at the second part of your requirement, playing a random music file. For that you can look at _FileListToArray in the help file, and grab all files from a directory:

#include <Array.au3>
#include <File.au3>

Local $aMusic = _FileListToArray(<path to music files>, "*.MP3", $FLTA_Files, True)
    _ArrayDisplay($aMusic)

Then you can look at different ways to parse through the array and choose your songs, based on your needs (look at Random in the help file as a place to start).

Bleh, too slow :)

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

#include <Array.au3>
#include <File.au3>

Local $aMusic = _FileListToArray("C:\Users\Jaro\Music\Trap", "*.MP3", $FLTA_Files, True)
SoundPlay("$aMusic/*mp3")

how can i change this to play a random file of the grabbed files in $aMusic

Link to comment
Share on other sites

3 hours ago, Ancrion said:

how can i change this to play a random file of the grabbed files in $aMusic

_ArrayShuffle is your friend.

 

Btw, did you checked what I've posted above?

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...