drupal's audio module

Updated for Drupal 5.1! See the bottom of the article.

I have a growing backlog of stories that I've been meaning to type up here, including several articles of interest for folks getting started with drupal, but I've just finished setting up the audio module, so I thought I'd share my experience while it's fresh on the mind.

You'll notice that you can now play the "two out of three" mp3 from my last post direct from the site without the need to download, and this is thanks to the audio module. Since it utilizes drupal's node model for content types, this module is able to harness much of the power and flexibility inherent in the CMS, including the taxonomy system and automatic RSS/podcast feed generation. It can also be readily extended through modules like the playlist toolkit for sites with sophisticated audio needs.

My intent here, though, is just to offer a quick step-by-step guide for a simpler application: a blog or some other site seeking to include audio files attached to other content types (pages and stories, for instance). Still, this should be helpful for anyone getting started with the audio module.

Installation and Configuration

  1. Let's obtain the audio module from the project page. I'm using version 4.7.0 for this guide. Untar the file in your site's modules directory.

    > tar xzvf audio-4.7.0.tar.gz

  2. Next we need to download the getid3 PHP libraries and unzip the downloaded file into the same directory as audio.module.

    > unzip getid3-1.7.7.zip -d <yoursitepath>/modules/audio/

    Version 1.7.7 of getid3 is recommended in the audio module's documentation.

  3. Open the site in your browser and go to administer >> modules. Enable the audio, audio_attach and audio_getid3 modules. I don't need to add audio files in bulk or use cover art, so I don't use audio_import or audio_images. Configuration for those modules is not covered here.
  4. I don't want audio entries in my navigation menu, so I disabled "audio" and "browse by" at administer >> menus. You can optionally enable audio-related blocks at, you guessed it, administer >> blocks.
  5. You'll need to set user privelages according to your needs: at administer >> access control I gave my blog user "create audio" and "edit own audio" permissions in addition to the defaults.
  6. In order to attach audio nodes to other content types, we need to enable this capability for each type at administer >> settings >> content types. I first configured audio, disabling Attach Images and Attachments since I have the image_attach and upload modules enabled. I also disabled comments and promotion to front page. Then, enable Attach audio files for the content types that suit your needs. I did so for story. You might do the same for page, CCK types or others.
  7. Finally, check your settings at administer >> settings >> audio. Typical PHP configurations will default to a 2MB upload limit -- you'll probably need to adjust your php.ini as suggested if you haven't already done so. Disable Downloadable by default if you want to make it more difficult for users to save copies of your music. Check that settings on the metadata tags tab are to your liking, and check the getid3 tab to assure that your installation is detected correctly.
  8. That's it! You should now be able to create a new node -- of a type set up in step six -- with the option to attach an audio file. This will create an audio node behind the scenes, which you can browse (and edit id3 tags for) at yoursite.com/audio. If you don't want this behavior, uncheck Published when attaching the audio file to your node.

Taking it Further

Of course, if audio plays a more prominent role at your site, there's much more that you can do with the audio module, incorporating taxonomy, changing the look of the player, and so on. Here are some links to get you started.

Update for Drupal 5.1

For the most part, updating my audio module for use as outlined above was intuitive, with one exception: the audio_attach module has just been contributed to CVS for 5.x by zirafa. He's also contributed a new audio_playlist module, but I haven't tried that out yet. To get audio_attach (and get my existing nodes with attached audio back to working order), I checked out the audio module from CVS with the following commands:

> cd <yoursitepath>/modules
> cvs -z6 -d:pserver:anonymous:anonymous [at] cvs [dot] drupal [dot] org:/cvs/drupal-contrib checkout -d audio contributions/modules/audio

I installed the modules as normal and ran update.php. At this point I received an SQL error as the script attempted to set multiple primary keys for the audio_attach table. I manually set nid, aid and weight as primary keys using phpMyAdmin, and I was back in business. I've found that my Flash players are not visible when using the handy admin_menu module, but that probably shouldn't effect many of your users.

I'll try to update all of these instructions soon. In the meantime, comment if you have questions!

The nasty error: the player only supports 11,22,44 khz sample ra

the player only supports 11,22,44 khz sample rates..
What software and how exactly do you encode your files so that when you upload your files, they're accepted by the audio module?

Thanks a lot, I've been working on this to no avail

David.

sample rate issue

Hi David,

I did see this sample rate error the very first time I tried to upload an audio file, but after that it went away and I'm really not sure what, if anything, I did to fix it. From what I recall, I was later able to upload the same mp3 file that I had the problem with, no re-encoding or anything... I may be wrong, though.

So far I've used files encoded with iTunes -- 192 kbps VBR Medium High quality joint stereo. If you're using iTunes, there is a setting for sample rate that you may want to force to 44.1 kHz if you haven't already (or double check your encoder of choice).

Please post back if you find out more!

That's flash for you

The real problem is with Flash, it's just super picky about the sample rate. The other rates either don't play or have a chipmunk effect.

Just want to thank you for

Just want to thank you for this tutorial, it was very helpful! I go my audio working.
Thanks.

No Flash

I can't get my website to use a flash player instead of opening Quicktime within Firefox. I made the changes suggested on Changing Player Theme/Colors with no luck. Any suggestions on why this would be happening?

Same problem here

Very annoying. Have you got anywhere with this?

Drupal 5 hosted at Dreamhost. No flash players work at all…

(although they work fine on my wordpress install on the same server)

same problem here too... in

same problem here too… in either Firefox or IE, and with any of the flash players selected, it just loads quicktime instead!

file type handling?

See if Firefox is configured to use Quicktime for handling mp3 files — Preferences >> Content tab >> File Types. This may override a Flash player, though I’d suspect the opposite, that QT is the fallback.

Taking a very quick look at the code, player loading is somewhat dependent on your theme playing nice… try setting a different theme for your admin account and see if the Flash players load.

audio module doesnt play after upgrade to drupal 4.7.4

i had the audio stuff working great and then i upgraded to drupal 4.7.4 from 4.7.0 and now clicking the play button for audio doesn’t work, the little circle just keeps spinning but there’s no sound. the audio.playlist’s player doesn’t work either now. also the download link acts different than it did before, it brings up the browser dialog about saving or opening with an app, wheras before the browser handled it.

does any of this seem familiar to anyone?

Well Done

It took me all of 10 minutes to setup the audio module to enable podcasts and online streaming. Your instructions were great. Thanks for taking the time.

Ahhh

I have installed getID3 successfully.

I have got an mp3 at 44.1 khz

I have changed players, left it as default

and I have tried fiddling with the theme

but I have yet to see a single instance of the flash player!? is it just a myth or have I missed something so blindingly obvious that it’s impossible to notice.

suggestions appreciated!

Ross.

same here

same problem here, can anyone suggest a solution? or a site where we could find a solution?

The next step to take would

The next step to take would be checking error logs for possible insight into what’s causing the problem. Memory alloted to PHP is a common issue for a lot of things — might be a good first stop. Here’s a drupal.org support doc to get you started in either case.

XSPF player missing? here's

XSPF player missing? here’s one possible cause.

I found that if the MP3 file is not at a sample rate of 44100, 22050 or 11025 (see code in audio.module) or if Drupal Sample Rate field doesn’t contain those values then the XSPF media player will not show or appear on an audio node or view, instead just “Click to play” that opens Quicktime or whatever your browser defaults to.

You can see sample rates on the audio node edit page or via the following mysql query:

select n.nid, n.title, a.sample_rate
from node n
, audio a
where n.nid = a.nid;

E.g. if you see 32000, then you won’t get the embedded media player.

You can change the sample rate of your mp3 files using http://audacity.sourceforge.net or something similar.

Gareth

streaming audio in forum posts?

Hi…

I want to be able to stream audio content in forum posts… any way to do this with this mod?

I'm not intimately familiar

I’m not intimately familiar with Drupal forum modules (and there are a few of them), but I’d imagine this would be trivial if your module of choice treats forum posts as true nodes. Just configure the content type and enable audio attachments. If that’s not the case, you’ll probably have to seek some additional module or try to hack things together yourself.

Iv'e set up audio and it

Iv’e set up audio and it works fine http://www.abelsong.com/music except for one particular mp3 http://www.abelsong.com/music/sad-girls

I’ve checked this file and it has a 44.1 khz sample rate and a 192 bit rate

Any ideas?

Hi, I'm setting this up and

Hi, I’m setting this up and when I’ve uploaded mp3’s I get a “?” after each of the items like title, artist, album, etc…

Any idea how to fix this?