Associating mp3 files with xmms in gnome
When I first tried to double click an mp3 file in nautilus (Gnome's file browser), it tried to play the file in Helix. Helix (at least the version on my computer) doesn't play mp3s. I had previously installed mp3 support for xmms (you can get it from 3rd party repositories supported by atrpms), so naturally I wanted to use it for playing mp3s.
The easy way to associate the mp3 files that mostly works is to find an mp3 file, right click it, then click on properties. You can change the default 'action' on the 'Open With' tab. Just select /usr/bin/xmms for the program.
The problem is with trying to queue up multiple mp3 files. If you highlight a group of files and try to play them, only the last file will get played. Xmms is called for each individual file, which clears the playlist.
I created this small script in /usr/bin/xmms-play. It queues up all the files and plays them at once.
#!/bin/bash
# This script works by first making a playlist out of the scripts parameters,
# then .2 seconds later, it plays the playlist.
# Tell xmms to play our playlist in .2 seconds, unless xmms is already queued
# to play.
if [ ! -e ~/.xmms_play ]; then
nohup bash -c 'sleep .2; eval "xmms -p `cat ~/.xmms_play`"; rm -f ~/.xmms_play' >/dev/null &
fi
# This function returns the input parameter escaped. It does this by surrounding# the input by single quotes.
#
# The only character that can break out of single quotes is a single quote
# itself, which means the single quotes need to be escaped. It does this by
# replacing any single quote that appears within the input by '\''. Example:
#
# start ' end
# becomes:
# 'start '\'' end'
escape()
{
local replace="'\\''"
echo -n "'${1/\'/$replace}' "
}
# Take all of our parameters and add them to the play list
for file in "$@"; do
escape "$file" >> ~/.xmms_play
done
