[project @ 5597]
[audio-mpd.git] / lib / Audio / MPD / Status.pm
blobc3c4a7c0b39e7dac60aa7fd07eaa40dde8f5606b
2 # This program is free software; you can redistribute it and/or modify
3 # it under the terms of the GNU General Public License as published by
4 # the Free Software Foundation; either version 2 of the License, or
5 # (at your option) any later version.
7 # This program is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 # GNU General Public License for more details.
12 # You should have received a copy of the GNU General Public License
13 # along with this program; if not, write to the Free Software
14 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 package Audio::MPD::Status;
20 use warnings;
21 use strict;
23 use base qw[ Class::Accessor::Fast ];
24 __PACKAGE__->mk_accessors
25 ( qw[ audio bitrate error playlist playlistlength random
26 repeat song songid state time volume xfade ] );
29 #--
30 # Constructor
33 # my $status = Audio::MPD::Status->new( @output )
35 # The constructor for the class Audio::MPD::Status. @output is what MPD
36 # server returns to the status command.
38 sub new {
39 my $class = shift;
40 my (@output) = @_;
42 my $self = {
43 map { /^([^:]+):\s+(.+)$/ ? ($1 => $2) : () }
44 @output
46 bless $self, $class;
47 return $self;
52 __END__
54 =pod
56 =head1 NAME
58 Audio::MPD::Status - class representing MPD status
61 =head1 SYNOPSIS
63 my $status = $mpd->status;
66 =head1 DESCRIPTION
68 The MPD server maintains some information on its current state. Those
69 information can be queried with the C<status()> method of C<Audio::MPD>.
70 This method returns an C<Audio::MPD::Status> object, containing all
71 relevant information.
73 Note that an C<Audio::MPD::Status> object does B<not> update itself regularly,
74 and thus should be used immediately.
77 =head1 METHODS
79 =head2 Constructor
81 =over 4
83 =item new( @output )
85 The C<new()> method is the constructor for the C<Audio::MPD::Status> class.
86 It is called internally by the C<status()> method of C<Audio::MPD>, with the
87 result of the C<status> command sent to MPD server.
89 Note: one should B<never> ever instantiate an C<Audio::MPD::Status> object
90 directly - use the C<status()> method of C<Audio::MPD>.
92 =back
95 =head2 Accessors
97 Once created, one can access to the following members of the object:
99 =over 4
101 =item audio()
103 A string with the sample rate of the song currently playing, number of bits
104 of the output and number of channels (2 for stereo) - separated by a colon.
106 =item bitrate()
108 The instantaneous bitrate in kbps.
110 =item error()
112 May appear in special error cases, such as when disabling output.
115 =item playlist()
117 The playlist version number, that changes every time the playlist is updated.
119 =item playlistlength()
121 The number of songs in the playlist.
123 =item random()
125 Whether the playlist is read randomly or not.
127 =item repeat()
129 Whether the song is repeated or not.
131 =item song()
133 The offset of the song currently played in the playlist.
135 =item songid()
137 The song id (MPD id) of the song currently played.
139 =item state()
141 The state of MPD server. Either C<play>, C<stop> or C<pause>.
143 =item time()
145 A string with the time played so far and the total time of the current song,
146 separated by a colon.
148 =item volume()
150 The current MPD volume - an integer between 0 and 100.
152 =item xfade()
154 The crossfade in seconds.
156 =back
158 Please note that those accessors are read-only: changing a value will B<not>
159 change the current settings of MPD server. Use C<Audio::MPD> methods to
160 alter the settings.
163 =head1 SEE ALSO
165 You can find more information on the mpd project on its homepage at
166 L<http://www.musicpd.org>, or its wiki L<http://mpd.wikia.com>.
168 Regarding this Perl module, you can report bugs on CPAN via
169 L<http://rt.cpan.org/Public/Bug/Report.html?Queue=Audio-MPD>.
171 Audio::MPD development takes place on <audio-mpd@googlegroups.com>: feel free
172 to join us. (use L<http://groups.google.com/group/audio-mpd> to sign in). Our
173 subversion repository is located at L<https://svn.musicpd.org>.
176 =head1 AUTHORS
178 Jerome Quelin <jquelin@cpan.org>
181 =head1 COPYRIGHT AND LICENSE
183 Copyright (c) 2007 Jerome Quelin <jquelin@cpan.org>
186 This program is free software; you can redistribute it and/or modify
187 it under the terms of the GNU General Public License as published by
188 the Free Software Foundation; either version 2 of the License, or
189 (at your option) any later version.
191 This program is distributed in the hope that it will be useful,
192 but WITHOUT ANY WARRANTY; without even the implied warranty of
193 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
194 GNU General Public License for more details.
196 =cut