Automatically play music from USB Drive / Folder

Not sure if this was ever asked before, but I can’t seem to find an answer to wether this is possible or not:

I’m using multiple Raspberries with Volumio (up to 14) in a professional environment for playing music which are provided via USB Drives. Is it possible to just have Volumio play the contents of a connected drive or folder on that drive, withouth having to build a new playlist everytime?
Eventually they should all play from the same NAS - but even then I would like them to play the content of a certain folder on that NAS, so that I can just change the music in that folder, maybe reboot the Raspberries and have them all play the new content.

Bonus question: Would it be possible, via some scripting, to have Volumio automatically play from a USB drive as soon as it connects? For example, if I play a Webradio Stream on it for most of the time, but want it to play a selection of songs for a while which I have on a Drive, I’d like to be able to just pop in that drive and have Volumio just play its content, and after disconnecting continue playing the stream (not sure if that’s possible but would be great!).

Thanks in advance, any answer will be appreciated! :slight_smile:

So is it not possible to play music from a USB drive without creating a playlist? Doesn’t anybody know? :frowning:

You have to add some custom scripts that get executed whenever a USB drive is mounted (there is a config file in /etc) and that scan the new drive for files, adding everything they find to the mpd playlist.

You have to write the scripts yourself… they are not provided.

I have just wrote a script to do something very similar which could be amended.
I download podcasts to a USB drive and want the next one to auto play when I insert the USB drive.

The podcasts are stored on a specific USB stick in folder /podcast.
My script uses a timestamp so when next inserted it will play the next oldest file.

So log into volumio:
$ ssh volumio@volumio.local
Password: volumio

Create a bash script:
$ vi playPodcast.sh

[code]#!/bin/bash -

podcastfolder="/mnt/USB/podcast"
stampfile="$podcastfolder/timestamp"
set -x
exec > /home/volumio/errlog.txt 2>&1

test -d “$podcastfolder” || exit 1
if [ -e “$stampfile” ]
then
lasttime="$(cat “$stampfile”)"
lasttime="$(date -d “$lasttime” +%s.%N)"
else
lasttime=0
fi

next="$(find “$podcastfolder” -type f -printf “%T@\t%p\n” | sort -k1,1n |
awk -v last="$lasttime" ‘/(mp3|ogg|flac|opus)$/ { if ($1 > last) {print; exit} }’ )"

test “$next” = “” && exit 0
read ftime fname <<< “$next”

echo “$(date -d “@$ftime” +’%F %T.%N’)” > “$stampfile”

while mpc status | grep -q ‘Updating DB’
do sleep 3
done
mpc --wait clear
mpc add “${fname//mnt/}”
mpc play
#[/code]

$ chmod u+x playPodcast.sh

If the USB drive is inserted it will appear at /mnt/USB. you can list files in volumio with ‘mpc ls USB’
Test the script with:
$ ./playPodcast.sh
$ cat errlog.txt

Because I only want this to run when I insert a specific USB stick I need its UUID:
[b]$ sudo -i

blkid[/b]

/dev/sdb1: UUID=“24D3-E29D” TYPE=“vfat”

Create a UDEV rule to run the script when that USB stick is inserted:
# vi /etc/udev/rules.d/90-local.rules

# udev rule to play podcast when insert USB stick ACTION=="add", SUBSYSTEM=="block", KERNEL=="sd?1", ENV{ID_FS_UUID}=="24D3-E29D", RUN+="/home/volumio/playPodcast.sh"

Reload UDEV rules
# service udev reload

and thats it.

To play everything in the root folder you could use the command ‘mpc ls | mpc add’ (see linux.die.net/man/1/mpc for commands)

hi,
when i run the script, the usb stick is not mounted.

ls /mnt/USB and

mpc ls USB

are empty.

Is there something to consider to run the script in the correct order (after volumio has mounted the USB stick) ?

I use volumio 2.0.41.

If your usb has a name for example “Music” then to list it’s content the command is

ls /mnt/USB/Music