How do I automatically detect and display the length of a MP3 in a Wordpress post?
November 17, 2012 2:00 PM   Subscribe

I need a way for Wordpress (or a plugin) to automatically detect and display the length of a podcast/MP3.

I run a church website and we post audio sermons each week. I could simply type the length of each sermon in the comments section of the display page... I would like a way for Wordpress to automatically detect and display this. I can't find a plugin which will do it. Any suggestions? My site is here: http://sermons.aisquith.org
posted by brownrd to Computers & Internet (11 answers total) 1 user marked this as a favorite
 
Response by poster: Probably should have made that a link. Here it is: Aisquith Presbyterian Church Sermons.
posted by brownrd at 2:04 PM on November 17, 2012


I'm sure it's not that hard to get PHP to pull the metadata from the mp3 and then display that in Wordpress. I did notice on your page that when I click on a mp3, the remaining time display is really wonky, the number keeps bouncing around in different directions. Do you see that on your end?
posted by phaedon at 2:36 PM on November 17, 2012


Response by poster: Phaedon, yeah. That's the flash-based player that I currently use. By the time the entire MP3 downloads, it eventually gets the remaining time right. That will be replaced in the not-too-distant future.
posted by brownrd at 2:38 PM on November 17, 2012


MP3s don't have metadata. Some MP3s might have time info in the id3 tag, but that's at the end of the file so you don't get it until the download is complete.
posted by ryanrs at 3:19 PM on November 17, 2012


Well ID3 is a metadata container so I'm not sure what you might mean when you say mp3s don't have metadata. According to this article, if you use an HTML5 player you can preload the mp3's duration info.

This is a little bit out of my field so I don't have a specific plugin to recommend to get you started.
posted by phaedon at 3:30 PM on November 17, 2012


A radio host whose website I manage uses Podpress to do this and it works.
posted by steinsaltz at 4:03 PM on November 17, 2012


The playtime should be part of the id3 metadata... there's a good answer here for how to extract that data in PHP, via Stack Overflow user Sorvahr: (copied here in case that link goes stale)
You may use the getID3 library to read the file's metadata. There is a attribute called playtime_length (also see this code example) that you can read and convert to a floating point number using the php floatval() function.
AFAIK there are no WP plugins using the getID3 library, so this solution requires you roll your own hack (either your own custom plugin or some code in your functions.php) to extract the metadata.

The keen reader should also keep in mind that ID3 text is independent of file data (that is to say, a file's metadata might say it's X:XX long, when the track is actually Y:YY long), so while this solution should be fine for applications like this where you're just displaying a value to the user, if you're doing anything where you need that number to correlate with the actual duration of the MP3, you may want to find some way to derive it from the data itself (as opposed to the metadata).
posted by myrrh at 6:05 PM on November 17, 2012


I use Podpress for my podcast (see my Projects), and its issue with determining song length is that it has to load the whole song into memory - and the limited memory on the server usually keeps this from being useful. Instead there's a time field that I manually type in, which is then displayed on the page and in the podcast feeds.

If you switched from Sermon Browser: Podpress doesn't handle uploading files to the server, but it does include HTML5 players, for some mobile devices and browsers. It looks like various other feature requests for Sermon Browser are already built into Wordpress or Podpress.
posted by Pronoiac at 7:28 PM on November 17, 2012


Blubrry's Powerpress plugin for WordPress has auto length detection for .m4a/.mrv/.mp4 files.
posted by colorproof at 8:40 PM on November 17, 2012


I use Podpress for my podcast (see my Projects), and its issue with determining song length is that it has to load the whole song into memory - and the limited memory on the server usually keeps this from being useful.

Just want to point out also per colorproof's link that it's possible to preload the metadata without the entire song in HTML5.
posted by phaedon at 9:56 PM on November 17, 2012


Response by poster: Well, I cheated - I went to the Sermon Browser forum (I didn't expect anyone there would be able to help... but I wuz wrong..)

If you're interested in the solution, it's right here.
posted by brownrd at 12:56 PM on November 18, 2012


« Older How do I make dessert go to eleven?   |   Need a gift for a really nice guy! Newer »
This thread is closed to new comments.