KenP
Posts: 14
Joined: Sun Jun 17, 2012 6:13 am

Distro for a headless MP3 player?

Tue Oct 30, 2012 5:02 pm

Hi folks

It might sound like a waste of a Pi, but it's something I'm interested in. Might evolve the concept later, might scrap it and repurpose later. Anyway...

Which distro should I be looking at? Should have decent sound support (from the analogue headphone output), but no GUI is required. The idea is that when it powers on, it fires up the MP3 player (haven't even looked into that yet, but I'm sure there's plenty of choice) with random selection from a playlist (or folder) for a set duration, after which it either shuts down completely or just stops playing.

Obvious next evolution would be a push-button to restart the music (or add 30 minutes to current play duration) so that it doesn't have to be power-cycled to get it started.

The Pi will eventually be mounted inside the housing of a 2.1 stereo amp (I'll take care to keep it away from the magnets) and become invisible.

Thoughts? Ideas? Arguments?
Opinions expressed in this message are not necessarily those of the author.
I don't know where they come from.
It scares me sometimes.

0_nvd_0
Posts: 29
Joined: Sun Oct 14, 2012 10:12 pm

Re: Distro for a headless MP3 player?

Wed Oct 31, 2012 11:10 am

Use the Raspbian “wheezy” image provided on the download page.

Login as a normal user (raspberry) and create a password for the root so that you can login as root. It is easier to do stuff as root.

Code: Select all

sudo passwd root
Enter a password for the root and confirm it. Logout and login as root.

Install mplayer:

Code: Select all

apt-get update
apt-get install mplayer
In order to run the player on startup, ask the cron daemon.

Code: Select all

crontab -e
Add a job "@reboot play-music" without quotes.
"play-music" is a script that will mount the flash drive, generate a fresh playlist and start playing it indefinitely.
It is good to have an external flash drive to contain all the music so that it is easily removable for updating the music files.

"play-music" script generation:

Code: Select all

nano /bin/play-music
Add these lines to the file:

Code: Select all

#!/bin/bash
mount /dev/sda1 /mnt/music
cd /mnt/music
find -type f -iname "*.flac" -or -iname "*.ogg" -or -iname "*.wav" -or -iname "*.mp3" | sort -R > playlist
mplayer -playlist /mnt/music/playlist -loop 0
Type "Ctrl + x" followed by "y" and Enter to save the changes.

It will create a random playlist each time RPi is booted. If you want the list to be sorted, remove "-R" switch from the "sort" command.

To make the script executable, type:

Code: Select all

chmod +x /bin/play-music
Create the mount point for the external flash drive.

Code: Select all

mkdir /mnt/music
You have to make sure that the flash drive is detected as "/dev/sda1".
Connect the flash drive and type-in:

Code: Select all

fdisk -l
If there is no other flash drive connected, "/dev/sda1" is the most probable name.

It is good to keep the flash drive formatted for FAT32 for compatibility with Windows.

This project can evolve if someone does the testing and posts the feedback here.

Next steps:
1: Not to start the services that are not needed. It will help in quicker boot time.
2: Make the SD card read only so that no OS corruption occurs due to power failures or other reasons.

Here is a good reference for playlist generation:
http://zuttobenkyou.wordpress.com/2009/ ... r-mplayer/

And it is NOT a waste of Pi. Melodies are honey for ears. ;)

jj_0
Posts: 3
Joined: Wed Jul 11, 2012 7:07 am

Re: Distro for a headless MP3 player?

Wed Oct 31, 2012 3:20 pm

You could have a look at http://www.raspberrypi.org/phpBB3/viewt ... 35&t=19799, though it might be overkill for what you want.

User avatar
fdion
Posts: 307
Joined: Sun Sep 16, 2012 2:33 pm
Location: North Carolina, USA
Contact: Website

Re: Distro for a headless MP3 player?

Wed Oct 31, 2012 3:28 pm

Another thing to investigate is to use the -slave mode of mplayer:

http://www.mplayerhq.hu/DOCS/tech/slave.txt

It is then possible to build a quick and dirty "front end" in python with GPIO support for the buttons, or with web.py for a web control. You want a way to skip a song you just dont feel like hearing at a particular point.

Also, for the storage, instead of using a flash drive, if you are on the network, you could mount a folder using NFS from your unix/linux/mac PC or server. Or using samba if the PC runs windows.

François
Francois
http://raspberry-python.blogspot.com - http://www.3dFutureTech.info - @f_dion

0_nvd_0
Posts: 29
Joined: Sun Oct 14, 2012 10:12 pm

Re: Distro for a headless MP3 player?

Wed Oct 31, 2012 3:48 pm

Another possibility is to make RPi a WiFi access point; good for use in a car.

Have a look at:
http://www.raspberrypi.org/phpBB3/viewt ... 36&t=14100

Once you enter the car, your Android based phone automatically connects to RPi through WiFi.

Afterwards, SSHMote can be used to control it as a player.
https://play.google.com/store/apps/deta ... NobW90ZSJd

Good thing is that your friends can also connect to it and browse the music without using your phone.

But, in room, one can connect RPi to the network through ethernet if your router is already WiFi enabled.

AlexF1980
Posts: 3
Joined: Tue Jul 17, 2012 1:50 pm

Re: Distro for a headless MP3 player?

Sun Oct 06, 2013 9:25 pm

Hey folks, I've tried running this script from the pi user crontab but mounting the USB memory stick always fails.

I can manually mount it outside of crontab though.

Do I need to use the root account to make the mount script work?

0_nvd_0
Posts: 29
Joined: Sun Oct 14, 2012 10:12 pm

Re: Distro for a headless MP3 player?

Mon Oct 07, 2013 8:04 am

Please share the crontab script; "crontab -e"

Also make sure to add PATH variable to the top of the crontab file:
(Possibly "mount" is not accessible without the "PATH")

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

AlexF1980
Posts: 3
Joined: Tue Jul 17, 2012 1:50 pm

Re: Distro for a headless MP3 player?

Mon Oct 14, 2013 6:49 pm

0_nvd_0 wrote:Please share the crontab script; "crontab -e"

Also make sure to add PATH variable to the top of the crontab file:
(Possibly "mount" is not accessible without the "PATH")

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Apologies for my delayed reply...

Here you go:

Code: Select all

# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h  dom mon dow   command
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
@reboot play-music
@reboot ./fmtx 8750
My pi will reboot and fire the ./fmtx command, but the mount command in the play-music script doesn't work from crontab:

Code: Select all

#!bin/bash
mount -t vfat -o uid=pi,gid=pi /dev/sda1 /mnt/music
cd /mnt/music
find -type f -iname "*.flac" -or -iname "*.ogg" -or -iname "*.wav" -or -iname "$
mplayer -ao alsa:device=hw=1.0 -playlist /mnt/music/playlist -loop 0
my guess is that the mount command above needs "sudo" to run outside of any script; is there a way of firing that as the pi user using crontab?

0_nvd_0
Posts: 29
Joined: Sun Oct 14, 2012 10:12 pm

Re: Distro for a headless MP3 player?

Mon Oct 21, 2013 11:50 am

Use "fstab" to automount the filesystem on startup.

https://access.redhat.com/site/document ... fstab.html

bdm
Posts: 1
Joined: Tue Nov 05, 2013 2:01 pm

Re: Distro for a headless MP3 player?

Tue Nov 05, 2013 2:05 pm

I would like to use my headless RPi as a player to stream a single internet radio station. Can this setup be used to accomplish this?

While waiting for my initial post to be approved I found this thread that looks like it should take care of my needs. I am open to any better suggestions that anyone has. Thanks.
http://thenated0g.wordpress.com/2013/06 ... dio-build/

0_nvd_0
Posts: 29
Joined: Sun Oct 14, 2012 10:12 pm

Re: Distro for a headless MP3 player?

Tue Nov 05, 2013 4:56 pm

Can this setup be used to accomplish this?
Yes.

mplayer -playlist "URL-of-the-Station"

penbrock
Posts: 2
Joined: Tue Nov 18, 2014 7:37 pm

Re: Distro for a headless MP3 player?

Tue Nov 18, 2014 7:41 pm

Has anyone found a way to have this auto start when the thumb drive is installed?
So You can play the files on one drive, take it out and plug in another and have it start playing the new files without the need to reboot?

0_nvd_0
Posts: 29
Joined: Sun Oct 14, 2012 10:12 pm

Re: Distro for a headless MP3 player?

Wed Nov 19, 2014 10:14 am

Use "udev" rules to launch a script to handle this.

Return to “General discussion”

Who is online

Users browsing this forum: jojopi and 27 guests