Play random music from a folder

gkld

New member
I am looking for something like on a trigger from a folder in my device some random file can be played.

How to do it?
 

RSF

Well-known member
The attached macro picks a file at random from a folder, then plays it (assuming it's a media file). You could add whatever trigger you like to it.

Note that you'll need to update:
  1. the value of the music_folder local variable, to be the folder from which you want to pick a random file
  2. the value of the writeable_folder local variable, to be a folder that MacroDroid can write to (later versions of Android are very picky about which folders apps can write to; the Documents folder seems to work)
If you wanted another app to play the music file (e.g. PowerAmp, or YouTube Music, or Spotify, etc.), you'd want to replace the last set of actions with whatever your app needs (presumably a Send Intent action of some sort). You could get rid of the writeable_folder local variable in that case, as well.
 

Attachments

  • Play_random_file.macro
    9.1 KB · Views: 43
Last edited:

gkld

New member
Hi,
I can see that files are loaded in the variable and a dialogue box is also displayed but file is not played.

please help!!!

sending the link
 

Attachments

  • MacroDroidLog - Copy (2).txt
    1.2 MB · Views: 13

gkld

New member
Hi Jacob.
I didn't understand this macro at all.

It worked be highly appreciative of you can modify and send so that it is ready to use.

It may be helpful for others also.

Thank you Jacob
 

RSF

Well-known member
I didn't understand this macro
That macro is similar to the one I'd posted. It:
  1. Gathers a list of music filenames, via Shell Script actions which utilize Android operating system commands to find and store music files' names
  2. Picks a file using a randomization scheme
  3. Plays that file
@Jacob L 's macro needs you to have another app called Total Commander installed on your phone. That app plays the selected track (vs. using the built-in MacroDroid Play/Stop Sound action, as in my macro). Total Command also has the benefit of showing pause/stop etc. controls, which you'd have to implement yourself in MacroDroid if you used the built-in action.

So, to use his macro
  1. Install the Total Commander app
  2. Open it up and navigate around to your music files, and play one manually using the app -- that'll force Android to ask you to grant the app permissions to access files/play music/etc. You'll need those permissions to be in place, to use the intent scheme in Jacob's macro
If you wanted to restrict the macro to a specific folder, you could edit the shell script actions.


a dialogue box is also displayed but file is not played.
My guess is that MacroDroid hasn't been granted access permissions to the Documents folder, or maybe your Documents folder is at a different location than /storage/emulated/0/Documents/. It's probably easiest to try the Total Commander app scheme above vs. getting MacroDroid permissions to that folder, and having to implement Stop / Pause buttons...
 
Top