This is a read-only archive. Find the latest Linux articles, documentation, and answers at the new Linux.com!

Linux.com

Feature: Internet & WWW

Manage and play your audio files over the Web with Ampache

By Ben Martin on July 14, 2008 (4:00:00 PM)

Share    Print    Comments   

Ampache is a LAMP application that gives you a Web interface to your music collection, allowing you to search, rate, and play your music over the network. It even offers transcoding support to allow clients to play back lossless-encoded FLAC files from the server and stream them to clients as MP3 audio files.

Packages for Ampache are in the standard Ubuntu Hardy repository as well as a 1-Click install for openSUSE 11. No Ampache packages are in the Fedora repositories. For this article I'll build Ampache 3.4.1 from source on a 64-bit Fedora 8 machine.

I'll assume you have already installed LAMP. To set up Ampache, first extract it into your Web server's DocumentRoot, which is typically something like /var/www/html, as shown below.

# grep DocumentRoot /etc/httpd/conf/httpd.conf ... DocumentRoot "/var/www/html" ... # cd /var/www/html # tar xzvf /.../ampache-3.4.1.tar.gz # ln -s ampache-3.4.1 ampache # chown -R root.apache ampache*

Ampache uses a MySQL database, so you might as well set up a database and an administrator account with full access to that database. Make sure you change your passwords as you go.

# mysql -p mysql> CREATE DATABASE ampache; mysql> GRANT ALL ON ampache.* TO ampache@"%" IDENTIFIED BY 'ampachepass'; mysql> FLUSH PRIVILEGES; mysql> \q

To continue installation, open Ampache in your Web browser by loading http://127.0.0.1/ampache/. As you have taken care of possible file permission issues above, the only thing you need to have before you start the next phase of installation is the username and password of a MySQL account that can set up the Ampache database. The ampache user and password that you set up above is fine for this purpose. Installation is a three-step process. Step 2 asks you again for the username and password to use to connect to the database and allows you to download the ampache.cfg.php configuration file, which you must then copy to the Web server that you are running Ampache on. The below commands can be used on the machine running Ampache to install the configuration file.

# cp /.../ampache.cfg.php /var/www/html/ampache/config/ # chown root.apache /var/www/html/ampache/config/ampache.cfg.php # ls -lh /var/www/html/ampache/config/ampache.cfg.php -rw-r----- 1 root apache 19K 2008-06-27 20:42 /var/www/html/ampache/config/ampache.cfg.php

Step 3 of installation asks you to create the Ampache administrator account and password. Once you've completed this step you should see a standard Ampache login screen. Once you log in to the admin account, you should see in the row of buttons below the menu on the left side a button with a tooltip "Admin," which allows you to create new catalogs and users, set up access control, and perform other administration tasks. The main menu is on the left side of screen, the center part of the screen changes depending on what operation you are performing, and the playlist is shown on the right side of screen.

After you create your users, you need to tell Ampache where to find your music files. The "Add a Catalog" option in the admin menu asks for the catalog name and the path where the music files for that catalog are located.

Once you have added a catalog you can select the browse button (second from the left in the menu) to browse the music files in your catalogs by song name, album, artist, or other criteria. Clicking Albums from the browse menu on the left of screen showed the albums from my catalog directory correctly, and clicking the plus sign next to one of them added it to my playlist, which is shown on the far right of screen. The playlist has a small row of icons at its top for actions like starting playback, adding a new playlist, and clearing the playlist, and a dropdown menu for features such as random play and playing music that is "related" to your current playlist. By default, clicking on the play button of the playlist causes the Web browser to download an m3u playlist file. If you then open the m3u file in an application such as Amarok your playlist will appear and you can start playback. The m3u file that is downloaded includes HTTP URLs to your Ampache installation so that the audio files can be streamed from your server.

Ampache includes a Flash component to allow playback directly from within your Web browser. To use this, go to your preferences (the icon that is second from the right in your menu), go to the streaming section, and set Type of Playback to Flash player instead of the default of Stream. Once you nominate to use the Flash player, clicking on the play button of your playlist will pop up a new window with a limited playback interface and music should start playing. The Flash player supports only MP3 audio, but Ampache can transcode audio into different formats on the server for you, so you should be able to playback your FLAC files from the Flash player even when you are using a limited client machine.

Ampache ships with m4a audio transcoding enabled. An audio transcode needs four things: to be enabled, to have a source format, to have a target audio format, and to have a command that converts from the given source format into the target audio format. These configuration options are set in config/ampache.cfg.php, and options already exist for transcoding m4a, MP3, and FLAC audio, with the latter two disabled by default. I found that just by uncommenting the line transcode_flac = true in config/ampache.cfg.php, I could play FLAC files transcoded on the server to MP3 files before being sent to the Flash player. One issue I had was that I had to enable that option to playback FLAC files, but if I left that option enabled and reverted to Streaming playback, I would still get the transcoded MP3 instead of the FLAC playback from Amarok. There is mention of explicitly enabling transcoding for only remote IP addresses but I couldn't see any information on how to enable it only for clients that are using the Flash-based player. No matter what setting I selected for Transcoding in my preferences, unless transcode_flac = true was set in the configuration file I could not play transcoded FLAC files using the Flash player.

If you want to run the whole show from Ampache instead of downloading m3u playlist files, you can set up the Music Player Daemon on the machine that will be producing the sound and control that daemon directly from Ampache as detailed in these instructions. You can also use Amarok as your client to Ampache as detailed in the manual if you are willing to use the latest development version of Amarok.

Wrap up

For anyone with multiple clients, the ability Ampahce offers to move to any machine and see the same view of your music is attractive. The Flash client is a great option for allowing playback on embedded devices and set-top boxes with Flash capabilities. For a more seamless experience, using the Music Player Daemon under the control of Ampache lets you avoid the intermediate m3u files.

Ben Martin has been working on filesystems for more than 10 years. He completed his Ph.D. and now offers consulting services focused on libferris, filesystems, and search solutions.

Share    Print    Comments   

Comments

on Manage and play your audio files over the Web with Ampache

Note: Comments are owned by the poster. We are not responsible for their content.

Manage and play your audio files over the Web with Ampache

Posted by: Anonymous [ip: 216.26.129.17] on July 14, 2008 06:04 PM
GRANT ALL ON ampache.* TO ampache@"%" IDENTIFIED BY 'ampachepass';

Why would you allow access to the DB from machines other than the one running the front end???

#

Re: Manage and play your audio files over the Web with Ampache

Posted by: Anonymous [ip: 141.123.223.100] on July 14, 2008 06:27 PM
He doesn't understand MySQL security? :) In all fairness, I see this far too often in docs as the suggested method of granting access to users. Open Source SOFTWARE supposedly gets "many eyes" security reviews, but the docs....not so much.

#

Re(1): Manage and play your audio files over the Web with Ampache

Posted by: Anonymous [ip: 204.50.208.4] on July 14, 2008 06:32 PM
The example uses Ubuntu. I don't think security was at the forfront of the author's mind.

#

Re(2): Manage and play your audio files over the Web with Ampache

Posted by: Anonymous [ip: 203.94.188.15] on July 15, 2008 07:28 AM
No, the article uses Fedora. Please read :)

#

Manage and play your audio files over the Web with Ampache

Posted by: Anonymous [ip: 69.30.67.216] on July 15, 2008 01:18 AM
If the db is only accepting local connections then the db is not wide open. I haven't installed it myself, but I'd hope that it only requires local connections (daemon to db) and that this persons doc is then, just fine.

peas,
eylisian

#

Manage and play your audio files over the Web with Ampache

Posted by: Anonymous [ip: 164.61.216.35] on July 15, 2008 08:42 AM
Ampache is a great jukebox. It runs very nice on my Synology DS107e. IT may not be superfast but very stable.

#

Manage and play your audio files over the Web with Ampache

Posted by: Anonymous [ip: 78.186.192.165] on August 11, 2008 04:12 PM
First, I would like to extend my condolences to Joe's friends, colleagues, and his family. Even though I never met Joe, many of his articles helped me through the years. I will never be anywhere near as knowledgeable as Joe but thanks to people like him, I have a help website for new Linux users.

http://www.cinselsorular.com

#

This story has been archived. Comments can no longer be posted.



 
Tableless layout Validate XHTML 1.0 Strict Validate CSS Powered by Xaraya