Creating a child-friendly audio player with the Raspberry Pi
Preparation
Naturally, the player needs music before it can play. Ideally, the albums will be in a directory that the software can monitor for later changes. To create a local music directory, if one is not already available, enter:
mkdir /home/pi/Music
Because the bar code recognition utility zbarcam
cannot deal with UTF-8 character encoding, especially if titles contain diacriticals, you should convert the album titles in MP3 file ID3v2 tags [8] with rename.sh
(Listing 1), which I placed in my home directory (/home/pi/
).
Listing 1
Rename All MP3 Files
#!/bin/bash #rename.sh fs=$IFS IFS=$(echo -en "\n\b") for i in *.mp3; do id3v2 -A "$1" "$i"; done IFS=$fs
Before running the rename script, you need proper access rights, which the command
chmod a+x ~/rename.sh
establishes. Now, if I run the script on an album with the title Der Grüffelo from the directory in which that MP3 file resides, then the command
~/rename.sh "The Gruffelo"
accordingly sets the ID3v2 parameters for that title. The script in Listing 1 renames all titles in the relevant directory in one go.
The Audio Player
With its modular construction and loadable libraries, the XMMS2 audio player utility is designed to be controlled via a script and remote control. The player distributes tasks between xmms2d
, the server component, and xmms2
, the client, and runs as a daemon in the background; therefore, a login is not required. In Linux systems, a daemon is a program that runs in the background and makes services available, much like system services in Windows.
xmms2
automatically starts the launcher and builds your music library from the music files in the Music
directory:
$ xmms2 server import /home/pi/Music
The output of the
xmms2 search artist:*
command should list all of the titles in the database, so you can determine whether the procedure has worked. To monitor the music directory via the XMMS2 media library updater, you make it part of its configuration:
$ xmms2 config clients.mlibupdater.watch_dirs/home/pi/Music
Then, all you need to do is call up
xmms2-mlib-updater &
to start the automatic update of the library before you modify files or copy new files into the directory.
Buy this article as PDF
Pages: 8
(incl. VAT)