Amarok Sleep – Stop Playback After Specified Amount of Time

Amarok is my favourite music player. I like to listen to music when I go a sleep, but I don’t want the music to keep playing all night long. This is why I’ve added a sleep feature to radio.py. Unfortunately, Amarok doesn’t have a built-in sleep functionality, but the Amarok developers left open door for us to implement it with ease by means of interfaces allowing to control amarok from the command line.

The first solution uses Amarok itself. The Amarok developers have provided means of controlling Amarok via the command-line. So we’ll combine this with the sleep command, and run the following in a console:

sleep 120m; amarok --stop

This will cause Amarok to stop after 120 minutes. The sleep command takes a number and a suffix which can be one of s, m, h and d (for seconds, minutes, hours and days). You can use it to easily set the duration before the playback halts.

Another solution, a more general one, would be to use DCOP. Amarok provides a very extensive DCOP interface that allows to control most of its features, including of course stopping the playback. So we could also use

sleep 1h; dcop amarok player stop

To stop Amarok in one hour.

A little note about the last solution. This post is written for Amarok 1.4 and not 2.0 as I didn’t switch yet to KDE 4. DCOP was replaced in KDE 4 by D-Bus and the last solution would probably not work. However, you could probably easily adjust it to the new D-Bus interface.

One thought on “Amarok Sleep – Stop Playback After Specified Amount of Time”

Leave a Reply

Your email address will not be published. Required fields are marked *