Sign in to follow this  
Followers 0
Ancrion

Looking for Script to play random Music files with random breakes

6 posts in this topic

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 :)

Share this post


Link to post
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

 

1 person likes this

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

@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
1 person likes this

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

thank you very much

I asked for something that i can learn and unstand it, i haven´t asked for the whole script

Share this post


Link to post
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

Share this post


Link to post
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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
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
Sign in to follow this  
Followers 0