[project @ 5748]
[audio-mpd.git] / scripts / example.pl
blob228c89e51335b612d788702106f2cd5d1352af8d
1 #!/usr/bin/perl -w
2 use strict;
3 use Data::Dumper;
4 use Audio::MPD;
6 ### NOTE! ###
7 # THIS SCRIPT DOES NOT CONTAIN ERRORHANDLING, AND MAY THEREFORE FAIL ON
8 # CERTAIN ACTIONS
9 ############
11 #my $x = MPD->new('localhost',2100); # Do this for specifing server and/or port.
12 my $x = Audio::MPD->new('localhost', 6601);
14 print "Example: Shows Audio::MPD used to write mpc-like output\n\n";
15 print($x->get_title,"\n");
16 print("[".$x->{state}."] #".($x->{song} || 'n/a')."/".$x->{playlistlength}." ".$x->get_time_format."\n");
17 print("volume: ".$x->{volume}."% repeat: ".$x->{repeat}." random: ".$x->{random}."\n");
19 print "\n\nExample: Shows list of all files, directories and playlists in a specific directory.\n";
23 my @array = $x->listallinfo('Misc');
24 foreach(@array)
26 print $_->{'file'} || $_->{'directory'} || $_->{'playlist'},"\n";
31 print "\n\nExample: Shows how to get information from the playlist. \@playlist is a reference, so don't change it :)\n\n";
32 my $playlist = $x->playlist;
33 print "Song 1 filename: ".$playlist->[1]{'file'}."\n";
34 print "Song 2 time: ".$playlist->[2]{'Time'}." seconds\n";
36 my $foo = $x->get_time_info;
37 print "Current song info: \n";
38 print "Minutes: ".$foo->{'minutes_so_far'}."\n";
39 print "Seconds: ".$foo->{'seconds_so_far'}."\n";