Thu, 21 Nov 2002
Python MP3 and OGG player

I've been getting annoyed with the awful music playing interfaces available on Linux - when compared with the multiple views of the available tracks that WMP has (which is its only good feature, I must add :). So I've been thinking for some time that I should write something that has a track list viewer with filesystem-, artist- and album-oriented tree displays. I really don't want to have to write C++, which what Noatun (the KDE multimedia player) is written in.

So I've been investigating getting into PyKDE again, which is cool because I really like PyQT and PyKDE (and KDE as a whole, really). Writing a Python-based plugin for Noatun would require Python support in Noatun though, and that's not likely to happen.

In the last couple of days, I've been thinking about it from a different angle. I noticed a submission to PyPI: pymad. It's a Python wrapper around an MP3 playing library. A short search later told me that the Ogg Vorbis people also have Python wrappers. Toby (a friend) has already written the track listing viewer (as a part of an ID3 tag editor project). Adding a play button would be pretty trivial at this point... The code to play an Ogg Vorbis file is:

import ogg.vorbis, ao

audiofile = ogg.vorbis.VorbisFile(filename)
dev = ao.AudioDevice('oss')
while 1:
    buf = audiofile.read(4096)
    if buf is None:
        break
    dev.play(buf, len(buf))

To play an MP3 file instead, the code is the same except the audiofile is:

import mad
.
.
audiofile = mad.MadFile(filename)
.
.

We're just plugging the bits together, with some extra high-level logic. That's why I love programming in Python :)

path: /python | permanent link |
Gimboland randomness...

Gimboland has a link to GetContentSize today, so I ran our corporate website through it and it came out at 7.41% - while my personal log (this page) came out at 51%. I guess that's the big difference between a site set up selling a product and a site that have real information on it (or at least thinks it does ;).

He also talked about IR control of PCs and plaing multimedia (or sound in particular). This is a subject that's close to my heart - I'm waiting for the disk that'll turn my PS2 into a multimedia network client :)

path: /stuff | permanent link |