Play songs randomly and endlessly I made a profile in Tasker (it runs on boot) for my (rooted) Android box. The tasks are: 


screen always ON
play randomly all the songs from a dedicated folder. 


It works. But I need to play endlessly the songs in the folder when Tasker ends playing the last song.

What I'm looking for is to loop the action "play songs from folder" when it's ended but I don't know how. 

I tried a "Goto" but Tasker runs the task even if the playback runs. My Android box starts to slow down very fast because I think Tasker repeats the task endlessly and plays the first song repeatedly at the same time.

This is how it looks like at the moment (very simple) :

Profile : "On start up" -> Task "Music"

"Music":


Event action : "Stay awake"
Media action : Play media from folder / random

only tested :
Task action : Go to "2" 


How do I achieve the goal?
It appears that the action Media &rarr; Music Play Dir cannot play files for infinite times. I tried with multiple Maximum Tracks value (with(out) Random enabled) and reached the conclusion that the maximum number of time Tasker would play a media would not be more than the number of playable files in the working directory. 

Enough about failure. Let's come to business. I came up with this following simple approach of mine:  

We're going to list all the files in your working directory (the same directory where your media files are kept) and store it in a variable. We will randomly select a file from the previous output, get the duration of the file, play it, set Tasker to wait for that much duration, then loop back to where the random selection of a media file occurs. 

Actions


Files &rarr; List Files:


Dir: working directory where media files are kept
Match: *.mp3/*.wma/*.3gp
Variable: %tracks


This step list all the files with MP3, WMA and 3GP extension available in the working directory, creates an array %tracks and fill the path name of each file as a value in that array.

I learned this step from this post of UncleMike.
Variables &rarr; Variable Set :


Name: %max_tracks
To: %tracks(#)


We're creating a variable named %max_tracks and assigning the size of %tracks array as its value. This variable would be used only in next step.
Variables &rarr; Variable Randomize:


Name: %rand
Min: 1
Max: %max_tracks


This step randomly selects a value in the range 1-%max_tracks and assigns the randomly chosen value to %rand.
Media &rarr; Test Media:


Type: Music File Duration Tag
Data: %tracks(%rand)
Store Result in: %duration


This step finds the duration of randomly chosen (%tracks(%rand)) media file and assign the duration as a value to %duration.
Variables &rarr; Variable Split


Name: %duration
Splitter: :


It is my assumption here that all of your media files are less than 59 minutes 59 seconds in duration. The duration received in last action is in the format MINUTES:SECONDS. In this action, we're splitting variable %duration at :. This would store MINUTES in %duration1 and SECONDS in %duration2.
Media &rarr; Music Play:


File: %tracks(%rand)
Stream: Media


This step plays the randomly chosen media file. 
Task &rarr; Wait:


Seconds: %duration2
Minutes: %duration1


This step makes the Tasker wait for the amount equivalent to the duration the randomly chosen would be played for.
Task &rarr; Goto


Type: Action Number
Number: 3


This step repeats the cycle from action 3 for the purpose of playing another randomly chosen media file.


Note: The Variable Randomize action of Tasker could bug you if the files are very short in numbers. That's something I can't help with.