Mediaplayer Web-Interface

June 13th, 2008 admin

Today I finished the first version of my current hobby programming project. The goal of my project was to realize a mediaplayer based on a old but silent Desktop PC. I wanted this PC to host my MP3/Ogg music collection and to provide a very simple interface. I wanted the interface to be accessible from my workstation and from other remote devices - like a iPhone or Windows Mobile based devices - so that I could move the mediaplayer into a corner or my room - or into the basement.

A decided not to write another software mediaplayer but to concentrate on the interface. There are already tons of great players available as Open Source - so why not utilize them? So I made this design for my project:

The music files are stored in a folder on the local filesystem. The information about artist, album, track etc get extracted using a simple Perl script. This data is then imported into a PostgreSQL database.

The user interface is realized in Perl, too. It’s a simple CGI application hosted on a thttpd webserver. The interface offers a simplistic search page. The search is wrapped into SQL queries and send to the PostgreSQL server. The results are rendered as browsable lists. The user can either select single songs, all songs for a specific album or all songs of a specific artists. The selection will be stored as a playlist that gets persisted in the database, too.

When a songs gets played and the player finishes, one normally wants the player to start the next song in the playlist. Therefore a daemon process is necessary that watches over the playback, starts it and stops it. I decided to write this daemon in Java because Java offers a good threading API and good network support. One thread of the application watches over the Linux commandline mediaplayer used to play the files (mpg123 and ogg123 in this case). A second thread is used to implement a webserver interface to make the interprocess communcation as painless as possible. Using the integrated webserver the CGI application can start the playback of the next song in the playback with a simple query to http://localhost:8000/start. That’s nice :)

I added some more features every jukebox should have: volume control and a sleeptimer. As noted initially the software is finished now. I installed Xubuntu 8.04, thttpd, PostgreSQL, Perl, mpg123 and ogg123 and my scripts on the box, tweaked the user rights to allow the remote shutdown, copied my music archive onto a second partition and imported it into the database. The installation was a little tricky - but I think that’s OK when I’m be the only customer :) I’ve tested the player for about a week now and it performs nice - no big problems so far. Here are some more screenshots to give you a impression of the software.


This is the default page of the interface displayed in Mozilla 1.7.


You can search for artists, albums and songs. The results are displayed as lists.


The result list is played inside a frame so that you never have to scroll to use the command buttons.


This is the playlist. Items can be removed using the “-” icon.


The volume can be adjusted using a JavaScript based slider. On the inside aumix is used to control the volume.


This is the interface for the sleeptimer. It’s a nice feature when you can listen to the music while you’re in bed and you do not have to stand up again to turn the computer off. Once the timer has been set the remaining time will be displayed here. Of course you can always cancel the timer.

Posted in Uncategorized | Comments Off

How to kill a process with a given name?

June 6th, 2008 admin

This will kill a running firefox:

ps -A | grep firefox | perl -e ‘my $std = <STDIN>; $std =~ /(\d{1,5})/; `kill -TERM $1`;’

Posted in Linux / Unix | Comments Off

Logfile viewer for java.util.logging output

June 4th, 2008 admin

Yesterday I had to crawl through the log output of my application to find a bug. The files are quite big so I looked for a nice logfile viewer. I found many tools like Java log viewer for gnome or Java Log Viewer - but these are either ugly or lag the ability to filter the logs. So I wrote my own application that works with the default Java XML logging output (explained here). You can view the entire logfile or filter entries for severity, classname, error message or method name. If you want to give it a try, here is the download.

Posted in Coding, Projects | Comments Off

VirtualBox 1.6 on Solaris 10 8/05

May 9th, 2008 admin

This week Sun released VirtualBox 1.6. This new version introduced stable support for Solaris and Mac OS X as host systems. I wanted to give the software a try and downloaded the latest binary version for Solaris 10 AMD 64. The installation was easy - but not very successful. Right after the start VirtualBox crashed with the error message “Unable to load R3 module /opt/VirtualBox/VBoxDD VBox status code: -102 (VERR_FILE_NOT_FOUND)”. I searched around but didn’t find the missing file libdlpi.so.1 for AMD64 - so I stopped there and went to bed.
Today I found the solution for that problem described in the VirtualBox forum. Worked fine for me.

Posted in Uncategorized | Comments Off

VB Script to remove special characters from filenames

May 5th, 2008 admin

During the weekend I moved my music collection from my laptop (with Windows XP) to my workstation (running Solaris) using FTP. When I had a look at the files on my workstation a found that most german umlauts got lost during this process. So I wrote a little Visual Basic Script that can be used to mass rename files and thereby replace special characters with a user defined replacement. When unmodified the script replaces all german umlauts like "ä" with the common german replacement: "ae".

The script has to be encoded in ASCII, not Unicode - or the Windows script interpreter will fail. So I have put the script in a ZIP-Archive - you just have to extract the file and not to bother with encodings.

Click here to download the script.

Posted in Uncategorized | Comments Off

Howto use automated ZFS snapshots for backups

May 1st, 2008 admin

Software developers often suffer the same problem: after two and a half hours of working on a single source code file you suddenly realize that your last ideas were wrong. Then it’s good to have backups - not only of the original unchanged file - but also from changes made 30 minutes, 60 minutes and 90 minutes ago.
The normal approach would be to use cron to create and update one or more copies of your working copy (or home directory). But this approach fails if you have as many files in your projects as I do or if you want backups for a longer period of time.
The Solaris ZFS filesystem offers a nice solution for this: snapshots. Snapshots represent the state of your filesystem at a given point in time. You can create multiple snapshots of your filesystem and use them to access the filesystem as it has been at the time when the snapshot has been taken. Snapshots are a cheap operation on ZFS - they can be created instantly. And snapshots only require the drive space that the changes on the files require - there is no need to have multiple copies of unchanged files.

I use a cron-job to create a snapshot of the storage pool I use for the user data. Therefor I have this simple utility script:

#!/usr/bin/bash

POOL=tank

# get seconds since epoch
TIMESTAMP=`/usr/bin/truss /usr/bin/date 2>&1 | nawk -F= '/^time\(\)/ {gsub(/ /,"",$2);print $2}'`

# create the snapshot
zfs snapshot -r $POOL@$TIMESTAMP

Snapshots do not replace a backup on a second disk or other medium. I burn my data onto a DVD every two days. So there is no need to keep snapshots for more than two days - so I use a second cron-jon to delete all those snapshots. Here’s the script:

#!/usr/bin/perl -w

my $pool = "tank";
my $maxAge = 172800; # 2 days

# Get the snapshots for the storage pool
my $snapshotList = `zfs list -r -t snapshot -o name $pool`;
my @snapshots = split(/\n/,$snapshotList);
my $anzahlSnapshots = @snapshots;
my $dateThreshold = time() -$maxAge;
for(my $i = 1; $i < $anzahlSnapshots; $i++) {
  # Check the age of each snapshot
  my $snapshot = $snapshots[$i];
  my $snapshotDate = (split(/\@/,$snapshot))[1];
  # Delete the snapshot if it's older than $maxAge
  if($snapshotDate lt $dateThreshold) {
    `zfs destroy $snapshot`;
  }
}

Posted in Uncategorized | Comments Off

Moving to Solaris

April 29th, 2008 admin

I’ve been using Solaris 10 for quite a while now - mostly just to try it out and to test my software on it. Now I went one step further and removed Ubuntu Linux entirely from my machine. Here are some benefits and disadvantages (from a developers perspective) of doing so:

Benefits:

  • Solaris is rock solid.
  • dtrace provides a powerful infrastructure to trace your code deep into the operating system. This is very useful to find e.g. bottlenecks in your code.
  • ZFS is the filesystem of Solaris. It has really cool features like snapshots, volume management and good performance.
  • Many more server features - like containers, build-in Java support,…

Disadvantages:

  • Solaris is not as user-friendly as Ubuntu is. You still have to like the command line (e.g. there is no GUI to manage the installation and update of software).
  • You’ll have to learn a few new things about the different package management, different device names, …
  • There is limited support for multimedia hardware. Have a look at the hardware compatibility list to check whether or not your hardware is supported.

For me there is enough benefit to move over to Solaris. Nearly all the tools I used on Linux are available on Solaris, too. This includes PostgreSQL, MySQL, Perl, Ruby, NetBeans, Java, Firefox, Thunderbird, Sunbird, GNOME and more. So there are no differences in working once the operating system is set up and configured.

Posted in Uncategorized | Comments Off

NetBeans 6.1

April 29th, 2008 admin

Yesterday NetBeans 6.1 has been released. The new version offers mostly improvements and only few new features. The IDE now starts up about 40% faster and uses less RAM. New features are support for JavaScript (including support for refactorings) and the improved support for the MySQL database in the Database Explorer. The Release-Notes describe all changes in detail.

Posted in Coding | Comments Off

Small tool to visually request administrator rights on Vista

April 8th, 2008 admin

For the last few weeks I’ve been working on a update and maintenance software. To perform such updates or maintenance tasks a user usually needs administrators access to the system. For most *NIX systems it’s pretty easy to request these rights visually. E.g. on Linux you just run gksudo <program> to start the program as root. Then a nice looking password request dialog appears. On Microsoft Windows it’s not that simple. Users of XP or Vista can use the runas command to start a application in a different user context - but this is not visual. The command is a interactive shell command so the user has to interact with the commandline… on Windows… Generally not a very good idea :D
At least for Vista I found a nice and short solution. I’ve written a second application called CRunasW (C# Runas Work-around). CRunasW has a manifest that specifies that only administrators are allowed to start it. When a user starts the application a nice looking dialog will apear and ask for the username and password of a administrator account. The application takes one mandatory and one optional parameter. The mandatory parameter specifies the application to be launched in the context of the administrator. The optional parameter may specify arguments that will be passed to that application.

Let’s have a look at some examples:

This will start a shell for the administrator. Have a look at the program title!
CRunasW cmd

This will run a the helloworld application. “Hello World” will be passed as one argument
CRunasW helloworld.exe "\"Hello World\""

This will run a the helloworld application. "Hello" and "World" will be passed as two separate arguments
CRunasW helloworld.exe "Hello World"

You can download CRunasW here (2.6 KB). The binary release of the program is public domain.

Posted in Uncategorized | Comments Off

Sleep Timer for Windows XP

April 4th, 2008 admin

Some time ago (1, 2) I presented a script that I wrote to shutdown my Linux PC after a given amount of time. Now I don’t use my Linux PC for music and podcasts anymore. Instead I use my Notebook - that is far more convenient for this task. My notebook stands right next to my PC so I can watch videos or hear music and podcasts on it - all while I’m still working on my Linux machine.
My Notebook runs Windows XP for various reasons - so I cannot use my old shutdown script anymore. I wrote a simple Visual Basic Script that does more or less the same as the shutdown script for Linux. It waits for a given number of minutes and then turns the computer off. The new script doesn’t handle the Windows logoff sound - so if you want a silent shutdown you still have to turn it off manually.

Here is the script:

Dim WshShell, Args

Set WshShell = CreateObject("WScript.Shell")
Set Args = Wscript.Arguments

WScript.Sleep Args(0)*60*1000
WshShell.Exec("shutdown -s -f")

About the script: It’s as simple as it could possibly be. It will get the commandline argument and wait for the given number of minutes. After that any applications will be forced to quit and the PC will be shutdown to halt. The shutdown itself is done with the shutdown command - which has a delay parameter, too. Regrettably this will only take a delay < 100 seconds - so it won’t work without the delay beeing handled by the script.

Posted in Coding, Uncategorized | Comments Off