MPD Remote control script

Hey, i'm still looking for my best audio player. At the moment i'm testing MPD with Sonata as Front-end.

Unfortunately, mpd doesn't come with a remote controle system that can be used with my Logitech keyboard. So I managed to write mine.

You'll need Audio::MPD, which is aviable in Debian with libaudio-mpd-perl

#!/usr/bin/perl
# Script by Yoda-BZH http://blog.yoda-bzh.net
# v0.1
 
#use strict;
use warnings;
use Audio::MPD;
use Getopt::Long;
 
my($mpdIp, $mpdPort, $mpdPass, $mpd);
$mpdIp = "localhost";
$mpdPort = 6600;
$mpdPass = "";
 
my %opt;
 
GetOptions(
        \%opt,
        "h|help"                => \&usage,
        "i|ip=s"                => \$mpdIp,
        "p|port=i"              => \$mpdPort,
        "q|pass|password=s"     => \$mpdPass,
        "play"                  => \&play,
        "pause"                 => \&pause,
        "fastforward|next"      => \&fastforward,
        "rewind|previous"       => \&rewind,
);
 
 
sub usage() {
        print "Usage: $0 [-h|--help] [-i|--ip ip] [-p|--port port] [-q|--pass|--password password] action\n";
        print "Action can be :\n";
        print " [--play]\n";
        print " [--pause]\n";
        print " [--stop]\n";
        print " [--fastforward|--next]\n";
        print " [--rewind|--previous]\n";
        print "";
}
 
 
sub mpdConnect() {
        if($mpd) {
                return;
        }
        $mpd = Audio::MPD->new(hostname => $mpdIp,
                                  port     => $mpdPort,
                                  password => $mpdPass);
}
 
sub play() {
        mpdConnect();
        $mpd->play();
}
 
sub pause() {
        mpdConnect();
        $mpd->pause();
}
 
sub fastforward() {
        mpdConnect();
        $mpd->next();
}
 
sub rewind() {
        mpdConnect();
        $mpd->previ();
}
 
exit 1;

Haut de page