Writing

Software, technology, sysadmin war stories, and more. Feed
Wednesday, August 3, 2011

Ditching broken graphical music players for my own

I used to use my Linux boxes to play music at home and at work. At one point in time, my solution was xmms. However, that quickly wore thin and I had to do something about it. This is my story of how it worked, how it stopped working, and then how I replaced it.

Initially, all of my music was in MP3 format. It wasn't like that due to any form of piracy, but rather because that's what you'd generate after ripping tracks from your own CDs. Ogg Vorbis didn't exist yet. I had a bit of a complicated setup where I had the horsepower to actually decode and play these things on one box, but all of my storage was on another. My solution was to stream things via HTTP over my internal network.

This worked fine for a while. Then Vorbis came along. I was still drinking the kool-aid of "it must be better, even though it sounds the same" and decided to re-rip and re-encode everything. Soon, all of my music was coming from .ogg files instead of .mp3. That's when xmms started acting wonky.

Some combination of my "run this script to fetch a new track" and "jump to the end" and "streaming Vorbis over HTTP" and "aborting playing tracks" did not agree with it. Depending on where I caught it, sometimes it would scribble all over memory or free a bad pointer and segfault. Boom. There goes my player.

I tried to figure out what was going on, but when I saw a huge single function with tons of deeply-indented code, a huge loop and no call outs to functions coupled with threading, I ran away. It was time to find another solution.

I tried to build zinf. It wanted musicbrainz, which seemed to be some way to identify songs by their actual audio patterns. Given that I owned all of those CDs and had lovingly keyed in all of this metadata, I deemed that pointless and tried to disable it during the build. Nope. Okay, forget that one.

The next one I tried was ogg123. My thoughts were that it could be the core of some dumb little wrapper I'd write. But that didn't work, either, since it used libao, and libao would not resample things headed for my sound device. It was stuck at 44.1 kHz and I needed 48 kHz since my on-board audio was AC97 and wouldn't budge. So much for ogg123.

Finally, I landed on mplayer. It had been working well for my video needs, and it turned out to be just fine with audio files as well. Also, it had a neat "-slave" mode where it would take commands on a file descriptor and do your bidding. Awesome. 15 minutes later, I had a quick proof-of-concept hack which would run wget via popen() and kick off mplayer. It worked!

Over the next few days, I turned it into a long-running process which would accept commands over a Unix domain socket. Now I could poke it from other places and say "hey you, do this". It didn't have a graphical interface, but it turned out to not be necessary. All I wanted to see was the artist and track name, and that was easily solved with text. Who needs a fake equalizer display? Certainly not me.

Anyway, that's what I used to do when I cared enough to fight with this stuff just to hear music. Now, I just use a Mac and iTunes. Ahhh. So much better.