Introducing ZX2C4 Music

Update: source code available here.

A few months ago I switched website hosts from Netfirms to Site5, because Site5 had a good deal for a plan with unlimited bandwidth and disk space. The first thing I did was upload my entire music collection.

To access all of my music remotely via any internet-connected web browser, I wrote ZX2C4 Music, which is password protected to avoid the law, but if you’d like to view the interface just for curiosity, ask me in the comments section, and I’ll e-mail you a password. It uses PHP/MySQL for managing the music, hashing each file with an sha1, TagLib for reading tags, and JavaScript/HTML as an interface:

Search queries are done with AJAX, and playing is done with Flash, if available; otherwise it defaults to browser plug-ins. Soon I should add HTML5’s <audio> element support. Since Flash only supports MP3, the php backend optionally transcodes non-mp3 songs on the fly by using ffmpeg. Songs can be downloaded in zipped bundles by using the download basket feature. The web interface still needs some work, most notably scrolling-pagination for the song table, but it’s definitely usable. Many have pointed my attention to Ampache, but I found it too big and overwhelming. You can view the source code here.

Of course, the next step was writing a Qt or KDE application that interfaces directly with the web backend using Phonon. Meet ZMusicPlayer:

It downloads and displays a compressed and sorted xml listing of all the songs and their sha1s. The columns of the list automatically size optimally using an awesome algorithm that still needs some tweaking (why is subtracting 40 required on line 87?). Suggestions?

It plays the songs by passing the appropriate QUrl to Phonon, and this is where the trouble begins. The xine backend on KDE 4.1.2 just skips one song to another most of the time, and when it does miraculously play, seeking (via HTTP partial requests) is unavailable. The headers for each of the server responses for song file requests provide the appropriate parameters for HTTP seeking. Maybe this has already been fixed in trunk, but if not, I aught to investigate the problem as soon as I switch my 4.1.2 desktop completely to trunk. GStreamer with Qt 4.4 allows for proper streaming if a GStreamer HTTP plug-in is installed (gst-plugins-good includes a wrapper plugin for libsoup, which works, for those who don’t want to install the gnome vfs plugin), which is understandable. However, seeking only works for mp3 files; m4a files play but cannot seek, even though the pertinent response headers are the same for both file types. On the Windows backend, the seeking situation is hopeless, and on the OS X backend, songs do not play at all. Also, xine is the only one that emits the proper buffering signals. On some setups though, some of these problems go away. I still need to do some more thorough debugging.

If you’d like to download and build ZMusicPlayer, you can browse the source, clone the repository with git clone http://git.zx2c4.com/zmusicplayer.git, or download a tarball. Depending on your package setup, you may have to tinker with the includes for the phonon headers. I’d love to hear some suggestions, so leave comments below. Once I stabilize the Qt code, I’d like to develop some optional KDE extensions, particularly integration with the KDE’s keyboard shortcuts.

Also: I’ve switched from blogging on kdedevelopers.org to my own Wordpress blog so that anyone can post comments without requiring an approved account. So, comment away. If you wanted to comment on my first post, but were unable to, you can now comment here. To comment on this post, use the link below.

Update Oct 25, 3:31pm: Several of you have e-mailed me to say that the browser hangs when loading a unfiltered giant collection. This is indeed the case, as no current browser is able to write 10,000 rows to a table in a reasonable amount of time. This is why above I speak of “scrolling-pagination”, which means that the table would load 100 or so rows at a time, and then auto-populate the remaining rows in 100 row increments every time the user scrolled to near the end.

Tags: ,

24 Responses to “Introducing ZX2C4 Music”

  1. AnonymousCoward says:

    Have you thought about using an Amarok webservice for that? It should be much easier…

  2. @AnonymousCoward
    That’s a great idea, a perfect suggestion. Next step: Amarok webservice! I’ll get to work on that right away.

  3. Sacha says:

    Yeah amarok webservice would be easier for you so you dont have to recreate YAGIMP (Yet Another Great Interface for a Music Player)

  4. @Sacha
    Yeah, absolutely. Though I’d additionally like a small statically compiled Qt app that I can quickly open from others’ computers. Statically compiling Phonon is problematic, though… at least with Qt 4.4, anyway.

  5. Oszkar says:

    Hi, I’d like to check out the interface, if that’s ok…

    By the way: is that legal and all? You giving out free usage of your music?

    Anyway… Nice work! :)

  6. @Oszkar
    I’m not giving out free usage of my music; I’m just giving access only for the purpose of viewing the interface. That’s why I want to do it on an individual basis.

  7. Mik says:

    Hi there,
    I’d really like to view the interface that you created.
    Thanks in advance.
    Mik

  8. Dread Knight says:

    The interface is so simple and intuitive, great job.

    On the other hand, i think the name of the player (zx2c4) is a ‘worst case scenario” so i wouldn’t be a troll and flame you up.

  9. Jeffrey says:

    zx2c4 music – nice idea! How large is your library? What’s it take to install this on other servers?

  10. @Dread Knight
    Thanks. Yeah… when I finish stabilizing it and release it to the public, it will most likely renamed.

    @Jeffrey
    Around sixty gigs. I’ll release a nice installable package fairly soon, once all the kinks are worked out. I’m also considering switching from taglib to getID3 so that you don’t have to worry about compilation of taglib, but I’m still investigating.

  11. Frank Mulder says:

    (offtopic) Coltrane and Mingus are great. ;)
    (ontopic) Cool solution to play your music everywhere, and to always have a backup of your collection. Also: nice website host. :)

  12. mxttie says:

    holy moly.. interesting project you have there! :)

    btw, thanks for the hosting tip ;)

  13. Vlad says:

    Wow, good job with the interface. I would be really interested to see how you did it / the code. please send me the info :)

  14. @Vlad
    If you just want the source, check out http://music.zx2c4.com/source.php .

  15. Maki says:

    Whats with “You do not have the right to download, modify, distribute, install, copy, or use the following code for purposes other than educational reading.” at http://music.zx2c4.com/source.php, do you plan to make a decent tarball of the source or its still beta testers only?

  16. Matti says:

    hello, what a nice thing it’s just about what I am looking for since ages. easy and small.
    greats

  17. @Maki
    I aught to remove that and GPL the whole thing. After I work out the kinks, I’ll most likely GPL it all and release a tarball and installer script etc. Stand by…

  18. Hey! =)
    I’d be very interested in doing something similar on my server which I just moved to the hosting site you noted (which is really great, btw! =) ), but was wondering… does it run on the PHP version 4 they provide?

    Anyways, looking forward to see a distributed version, if you can hand me a tarball, even just to test, I’d be more than happy to try it out. =)

  19. @Riccardo
    Glad you dig Site5. :-) It does run on PHP4, but you can also set Site5 to use PHP5 by default by including an .htaccess in your root that has on its own line:
    AddHandler application/x-httpd-php5 .php

    I’ll have a pre-release tarball out sometime this weekend, so I’ll be sure to shoot you an e-mail.

  20. [...] Ideas of Jason Donenfeld « Introducing ZX2C4 Music [...]

  21. [...] to columns of a QTreeView, with N = 3 and R = .42, which is derived from my AutoSizingList class of ZMusicPlayer. It uses QTreeView’s sizeHintForColumn to determine Mi. So essentially, the problem is that [...]

  22. [...] just fixed three major blockers in ZX2C4 Music. I also moved the source into a public git. You can browse the diff here, download the patch here, [...]

  23. [...] I’ve written in under 100 lines of JavaScript (QtScript) a service for Amarok that plugs into ZX2C4 Music (ReadMe for ZX2C4 [...]

  24. Jane Goody says:

    My fellow on Orkut shared this link and I’m not dissapointed at all that I came here.

Leave a Reply