Permalink
Browse files

Added state checking

  • Loading branch information...
1 parent 8df1f68 commit 5e9918607babc35e7f35d57c9e6c07a9ec5a93ad @tadzik committed Dec 15, 2010
Showing with 24 additions and 1 deletion.
  1. +23 −1 lib/MPD.pm
  2. +1 −0 test.pl
View
@@ -9,10 +9,17 @@ class MPD {
method current-song {
# TODO: a proper Song object
my $s = mpd_run_current_song($!conn);
- my $ret = mpd_song_get_uri($s);
+ my $ret = mpd_song_get_id($s);
+ $ret ~= ": " ~ mpd_song_get_uri($s);
mpd_song_free($s);
return $ret;
}
+ method state {
+ my $s = mpd_run_status($!conn);
+ my $r = mpd_status_get_state($s);
+ mpd_status_free($s);
+ return <unknown stop play pause>[$r];
+ }
submethod BUILD(Str $host, Int $port) {
$!conn = mpd_connection_new($host, $port);
if mpd_connection_get_error($!conn) {
@@ -54,4 +61,19 @@ sub mpd_song_get_uri(OpaquePointer)
returns Str
is native('libmpdclient') { ... }
+sub mpd_song_get_id(OpaquePointer)
+ returns Int
+ is native('libmpdclient') { ... }
+
+sub mpd_run_status(OpaquePointer)
+ returns OpaquePointer
+ is native('libmpdclient') { ... }
+
+sub mpd_status_free(OpaquePointer)
+ is native('libmpdclient') { ... }
+
+sub mpd_status_get_state(OpaquePointer)
+ returns Int
+ is native('libmpdclient') { ... }
+
# vim: ft=perl6
View
@@ -5,4 +5,5 @@
use MPD;
my $a = MPD.new('localhost', 6600);
+say "State: {$a.state}";
say $a.current-song;

0 comments on commit 5e99186

Please sign in to comment.