2

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

  1. screen always ON
  2. 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":

  1. Event action : "Stay awake"

  2. Media action : Play media from folder / random

    only tested :

  3. Task action : Go to "2"

How do I achieve the goal?

1
  • Even after an edit, I still don't think the title is unambiguous or doesn't have more than a single meaning. Perhaps, others can make it much clearer.
    – Firelord
    Jan 29, 2016 at 12:49

1 Answer 1

1

It appears that the action Media → 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

  1. Files → 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.

  2. Variables → 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.

  3. Variables → 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.

  4. Media → 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.

  5. Variables → 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.

  6. Media → Music Play:

    • File: %tracks(%rand)
    • Stream: Media

    This step plays the randomly chosen media file.

  7. Task → 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.

  8. Task → 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.

6
  • @moderator : Please don't delete this comment again because it's not only a "thank you" message Thank you very much, I'm very impressed by your work and I'm sure I couldn't find all of these tasks by myself ! In my folder, there are 45 songs. Do you think it's enough to avoid a bug ?
    – Lutte Cal
    Jan 30, 2016 at 9:20
  • Oh OK, sorry... Noob mistake. For the moment, I can't find any option to mark your answer as accepted.
    – Lutte Cal
    Jan 30, 2016 at 9:37
  • I was in beginner mode so I couldn't find how to assign the variables in task 7 but that's OK now :)
    – Lutte Cal
    Feb 1, 2016 at 8:29
  • You were right, the variable randomize action bugs me... I've tried to delete the action and play the songs alphabetically but, once again, I failed... Can you help me again ? Thanx.
    – Lutte Cal
    Feb 1, 2016 at 9:55
  • Not here. A poster is supposed to address the original query of the question, not the subsequent queries found somewhere in the comments. If you've a new question or an extension of the current, ask it as a new question.
    – Firelord
    Feb 1, 2016 at 12:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .