summaryrefslogtreecommitdiffstats
path: root/modules/mpd
diff options
context:
space:
mode:
Diffstat (limited to 'modules/mpd')
-rw-r--r--modules/mpd/CHANGELOG38
-rw-r--r--modules/mpd/COPYING340
-rw-r--r--modules/mpd/README58
-rw-r--r--modules/mpd/USAGE378
-rw-r--r--modules/mpd/mpd-class-example.php144
-rw-r--r--modules/mpd/mpd.class.php968
6 files changed, 1926 insertions, 0 deletions
diff --git a/modules/mpd/CHANGELOG b/modules/mpd/CHANGELOG
new file mode 100644
index 00000000..02453424
--- /dev/null
+++ b/modules/mpd/CHANGELOG
@@ -0,0 +1,38 @@
+========================================================
+* mpd.class.php - PHP Object Interface to the MPD Music Player Daemon
+* CHANGELOG
+* Copyright (C) 2003-2004 Benjamin Carlisle (bcarlisle@24oz.com)
+* http://mpd.24oz.com/ | http://www.musicpd.org/
+========================================================
+
+v1.2 - Released 05/05/2004
+ENHANCEMENTS
+* Program version compatibility table now does not allow incompatible commands to be sent to
+ the MPD. This is done to prevent sending outdated/incompatible commands.
+* Added new MPD v0.9.1 commands: PLMove(), SetRandom(), SeekTo()
+* Added MPD password authentication support.
+* Added GetArtists() and GetAlbums() functions.
+* Reflected 'volume' command deprecation in MPD v0.10.0
+
+BUGFIXES
+* None noted.
+
+
+v1.1 - Released 09/23/2003
+ENHANCEMENTS
+ * There is no longer the need to call RefreshInfo directly; it is automatically called upon
+ connection to MPD. Although this may be considered a bad move by some purists, I feel that
+ it substantially increases usability.
+ * Properties are now kept in sync with MPD. In other words, if a method call will modify a
+ MPD stateful variable (such as AdjustVolume()), it also will modify the object's property.
+ * Methods that manually retrieve MPD settings (GetVolume(), GetStatistics(), etc.) will soon
+ be deprecated. Instead, be a nice developer and use the object property (eg, $mpd->volume,
+ $mpd->uptime, etc.).
+ * Added the Find() method. Syntax is similar to Search().
+ * Although the command queuing (bulk command) methods were included in v1.0, they were not
+ documented. The QueueCommand() and SendCommandQueue() are now official methods.
+
+BUGFIXES
+ * None noted.
+
+v1.0 - Released 08/26/2003
diff --git a/modules/mpd/COPYING b/modules/mpd/COPYING
new file mode 100644
index 00000000..d60c31a9
--- /dev/null
+++ b/modules/mpd/COPYING
@@ -0,0 +1,340 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) year name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Library General
+Public License instead of this License.
diff --git a/modules/mpd/README b/modules/mpd/README
new file mode 100644
index 00000000..a5e40267
--- /dev/null
+++ b/modules/mpd/README
@@ -0,0 +1,58 @@
+========================================================
+* mpd.class.php - PHP Object Interface to the MPD Music Player Daemon
+* README Version 1.2, released 05/05/2004
+* Copyright (C) 2003-2004 Benjamin Carlisle (bcarlisle@24oz.com)
+* http://mpd.24oz.com/ | http://www.musicpd.org/
+========================================================
+[ABOUT]
+
+This class/API is a PHP interface to the MPD (http://www.musicpd.org/). Using
+this interface, you may write your own custom web-based interface to the MPD.
+
+In the event you want to talk with me, you may email bcarlisle@24oz.com. I am
+also a relatively frequent visitor of #mpd on FreeNet, under the nick of 'moot'.
+
+More information can be found at the MPD-Class Homepage, http://mpd.24oz.com/.
+
+[CONTENTS]
+The distribution contains the following files:
+
+mpd.class.php The mpd object PHP file.
+mpd-class-example.php An example (simple!) interface using the class.
+README This file
+USAGE Brief class documentation
+COPYING GNU Public License
+
+
+[HISTORY]
+I wrote this program in order to supplement the wonderful MPD in my own home audio
+environment. The interface that is supplied alongside MPD, called phpMp, worked, but
+was not as customizable as I would have liked.
+
+I currently use Netjuke (http://netjuke.sourceforge.net/) in order to catalog and
+locally play my MP3s, but I wanted a way to play songs through a playlist on my
+server.
+
+This class solved that problem -- I could integrate both pieces of software from a
+look-and-feel perspective and also allow one to talk to the other.
+
+This class has been tested with
+ PHP 4.2.1, 4.2.3
+ MPD 0.8.x, 0.9.x, 0.10.x
+
+[INSTALLATION]
+To install this php class, you simply need to place it in a directory that may be
+include()ed by PHP, and call require('mpd.class.php'). You may also place it in your
+PHP Include Path.
+
+[DOCUMENTATION]
+Please see the USAGE document for class methods/properties and examples on how to use
+this class.
+
+[CREDITS]
+Thank you to the MPD folks. You've put together a very easy-to-use and stable music daemon.
+Another big thanks to Netjuke folks... absolutely great program!
+
+[LICENSE]
+MPD is released under the GNU Public License.
+
diff --git a/modules/mpd/USAGE b/modules/mpd/USAGE
new file mode 100644
index 00000000..fad03635
--- /dev/null
+++ b/modules/mpd/USAGE
@@ -0,0 +1,378 @@
+========================================================
+* mpd.class.php - PHP Object Interface to the MPD Music Player Daemon
+* USAGE Version 1.2, released 05/05/2004
+* Copyright (C) 2003-2004 Benjamin Carlisle (bcarlisle@24oz.com)
+* http://mpd.24oz.com/ | http://www.musicpd.org/
+========================================================
+
+[NOTES]
+
+The following document outlines the object properties and methods of the mpd.class.php
+PHP class. Please note that this PHP class relies heavily on the functionality within
+MPD, and that this document reflects the functionality as of the current release of
+MPD (0.10.3).
+
+There are other object functions/properties that are not included in this documentation.
+They are either unsupported, untested, or, most likely, intended for calling within the
+object itself. You should be able to get along fine using only what is described below.
+
+
+[OBJECT INSTANTIATION]
+
+mpd(host,port,[password])
+Object constructor. When called, it will initialize all object variables and attempt to
+connect using the arguments supplied. If the connection attempt succeeds, data will be
+retrieved from the server and all appropriate class properties will be set.
+Note: if you're using MPD with a password, you must supply a password with at least read
+access to properly connect.
+
+
+ ARGUMENTS
+ host - the hostname upon which MPD is running
+ port - the TCP port on which MPD is listening
+ password (optional) - Authentication password for MPD server
+ RETURNS
+ mpd Object, upon success
+ EXAMPLE
+ $mpdObject = new mpd('localhost',2100);
+
+
+
+[PROPERTIES]
+
+The MPD Object, once instantiated, has the following properties:
+
+ mpd_class_version - The current version of MPD-Class.
+ mpd_version - The version string as returned by MPD.
+ connected - TRUE if it has properly connected to MPD, FALSE otherwise.
+ volume - The volume setting on MPD (1-100).
+ repeat - The status of the repeat (loop) flag. Either 1 (on) or 0 (off).
+ uptime - The number of seconds since the MPD server was started.
+ playtime - The number of elapsed seconds MPD has been actively playing.
+ num_songs - The number of tracks in the MPD database.
+ num_artists - The number of artists in the MPD database.
+ num_albums - The number of albums in the MPD database.
+ playlist_count - The number of tracks in the MPD playlist.
+ state - The current state of the MPD. Use constants:
+ MPD_STATE_PLAYING, MPD_STATE_STOPPED, MPD_STATE_PAUSED
+ num_songs_played - Number of songs played since MPD was started.
+ current_track_id - The playlist index of the currently playing track.
+ current_track_length - The length, in seconds, of the playing track.
+ current_track_pos - The position, in elapsed seconds, of the playing track.
+ errStr - The last error message returned. Empty if there was no error.
+ playlist - An multidimensional array containing the current playlist.
+
+
+
+[METHODS]
+
+Methods available for this class have been classified into several groups.
+
+ - Mixer Control Methods - For configuring mixer settings
+ - Player Control Methods - For controlling playback
+ - Playlist Maintenence Methods - For maintaining the MPD playlist, as well as stored M3U playlists.
+ - Searching/Browsing Methods - For locating tracks
+ - MPD Control Methods - Miscellaneous MPD control
+ - Other/Advanced Methods - Stuff that shouldn't be necessary, but are included ;)
+
+For the most part, you will not need the Other methods. They are included for Compatibility, as well
+as for use in my own code. You can do anything you need without using them, but use at your own risk!
+
+Mixer Control Methods
+SetVolume(vol) -
+ Sets the mixer volume on the MPD to <vol>.
+
+ RETURNS
+ NULL, upon failure
+ EXAMPLE
+ $mpdObject->SetVolume(75);
+
+
+AdjustVolume(vol) -
+ Adjusts the mixer volume on the MPD by <vol>.
+
+ RETURNS
+ NULL, upon failure
+ EXAMPLE
+ $mpdObject->AdjustVolume(-20);
+
+
+SetRepeat(1|0) -
+ Sets the repeat (loop) status to 1 (ON) or 0 (OFF).
+
+ RETURNS
+ NULL, upon failure
+ EXAMPLE
+ $mpdObject->SetRepeat(1);
+
+
+Player Control Methods
+Play() -
+ Begins playing the songs in the MPD playlist.
+
+ RETURNS
+ NULL, upon failure
+ EXAMPLE
+ $mpdObject->Play();
+
+
+Pause() -
+ Toggles pausing on the MPD. Calling it once will pause the player, calling it again
+ will unpause.
+
+ RETURNS
+ NULL, upon failure
+ EXAMPLE
+ $mpdObject->Pause();
+
+
+Stop() -
+ Stops playing the MPD.
+
+ RETURNS
+ NULL, upon failure
+ EXAMPLE
+ $mpdObject->Stop();
+
+
+Next() -
+ Skips to the next song in the MPD playlist. If not playing, returns an error.
+
+ RETURNS
+ NULL, upon failure
+ EXAMPLE
+ $mpdObject->Next();
+
+
+Previous() -
+ Skips to the previous song in the MPD playlist. If not playing, returns an error.
+
+ RETURNS
+ NULL, upon failure
+ EXAMPLE
+ $mpdObject->Previous();
+
+
+SkipTo(idx) -
+ Skips directly to the <idx> song in the playlist.
+
+ RETURNS
+ NULL, upon failure
+ EXAMPLE
+ $mpdObject->SkipTo(4);
+
+
+Playlist Maintenence Methods
+PLAdd(file) -
+ Adds the file <file> to the end of the playlist. <file> must be a song in the
+ MPD database.
+
+ RETURNS
+ NULL, upon failure
+ EXAMPLE
+ $mpdObject->PLAdd("U2 - Pride.mp3");
+
+
+PLAddBulk(fileArray) -
+ Adds each track listed in a single-dimensional <fileArray>, which contains filenames
+ of tracks to add, to the end of the playlist. This is used to add many, many songs
+ to the playlist in one swoop.
+
+ RETURNS
+ NULL, upon failure adding any track.
+ EXAMPLE
+ $mpdObject->PLAddBulk($songArray);
+
+
+PLRemove(idx) -
+ Removes the track located at position <idx> from the playlist. This will shift
+ the tracks behind it up one position.
+
+ RETURNS
+ NULL, upon failure
+ EXAMPLE
+ $mpdObject->PLRemove(2);
+
+
+PLClear() -
+ Clears the playlist entirely and stops playing MPD (if appropriate).
+
+ RETURNS
+ NULL, upon failure
+ EXAMPLE
+ $mpdObject->PLClear();
+
+
+PLSave(file) -
+ Saves the playlist to <file>.m3u for later retrieval.
+
+ RETURNS
+ NULL, upon failure
+ EXAMPLE
+ $mpdObject->PLSave("mysongs");
+
+
+PLLoad(file) -
+ Retrieves the playlist from <file>.m3u and loads it into the current playlist.
+
+ RETURNS
+ NULL, upon failure
+ EXAMPLE
+ $mpdObject->PLLoad("mysongs");
+
+
+PLShuffle() -
+ Randomly reorders the songs in the playlist.
+
+ RETURNS
+ NULL, upon failure
+ EXAMPLE
+ $mpdObject->PLShuffle();
+
+
+MPD Control Methods
+Disconnect() -
+ Close the connection to the MPD server.
+
+ RETURNS
+ Nothing
+ EXAMPLE
+ $mpdObject->Disconnect();
+
+
+Shutdown() -
+ Shuts down the MPD server (aka sends the KILL command). This closes the current
+ connection, and prevents future communication with the server.
+
+ RETURNS
+ NULL, upon failure
+ EXAMPLE
+ $mpdObject->Shutdown();
+
+
+DBRefresh() -
+ Causes MPD to refresh the database of its tracks.
+
+ RETURNS
+ NULL, upon failure
+ EXAMPLE
+ $mpdObject->DBRefresh();
+
+
+Searching/Browsing Methods
+Search(type,string) -
+ Searches the MPD database. The search <type> should be one of the following:
+ &nbsp;&nbsp;&nbsp;MPD_SEARCH_ARTIST, MPD_SEARCH_TITLE, MPD_SEARCH_ALBUM
+ The search <string> is a case-insensitive locator string. Anything that
+ contains <string> will be returned in the results.
+
+ RETURNS
+ Array containing search results, upon success.
+ NULL, upon failure
+ EXAMPLE
+ $results = $mpdObject->Search(MPD_SEARCH_ARTIST,"Met");
+
+
+Find(type,string) -
+ Similar to Search(), Find() looks for exact matches in the MPD database. The find <type> should be one of the following:
+ &nbsp;&nbsp;&nbsp;MPD_SEARCH_ARTIST, MPD_SEARCH_TITLE, MPD_SEARCH_ALBUM
+ The find <string> is a case-insensitive locator string. Anything that
+ exactly matches <string> will be returned in the results.
+
+ RETURNS
+ Array containing find results, upon success.
+ NULL, upon failure
+ EXAMPLE
+ $results = $mpdObject->Find(MPD_SEARCH_ARTIST,"Metallica");
+
+
+GetDir([dir]) -
+ Retrieves a database directory listing of the <dir> directory. If no
+ directory is specified, the directory listing is at the base of the
+ database directory path.
+
+ RETURNS
+ Array containing directory results, upon success.
+ NULL, upon failure
+ EXAMPLE
+ $humorArray = $mpdObject->GetDir("Humor");
+
+
+GetArtists() -
+ Retrieves a list of all artists in the database.
+
+ RETURNS
+ Array single-dimensional containing the list of artists, upon success.
+ NULL, upon failure
+ EXAMPLE
+ $artistArray = $mpdObject->GetArtists();
+
+
+GetAlbums([artist]) -
+ Retrieves a list of all albums in the database by a particular <artist> If no
+ artist is specified, all albums in the database are returned.
+
+ RETURNS
+ Array single-dimensional containing list of albums, upon success.
+ NULL, upon failure
+ EXAMPLE
+ $allAlbumArray = $mpdObject->GetAlbums();
+
+
+
+Other/Advanced Methods
+SendCommand(cmd,arg1,arg2...) -
+ Sends a generic command to the MPD server. Several command constants
+ are pre-defined for use (see MPD_CMD_* constant definitions in
+ mpd.class.php).
+
+ RETURNS
+ String containing server response, upon success
+ NULL, upon failure.
+ EXAMPLE
+ $response = $mpdObject->SendCommand("mycommand");
+
+
+
+QueueCommand(cmd,arg1,arg2...) -
+ Queues a generic command for later sending to the MPD server. The CommandQueue can
+ hold as many commands as needed, and are sent all at once, in the order they are queued,
+ using the SendCommandQueue() method. The syntax for queueing
+ commands is identical to SendCommand().
+
+ RETURNS
+ NULL, upon failure.
+ TRUE, otherwise.
+ EXAMPLE
+ $response = $mpdObject->QueueCommand(MPD_CMD_ADD,"myfile.mp3");
+
+
+
+SendCommandQueue() -
+ Sends all commands in the Command Queue to the MPD server.
+
+ RETURNS
+ NULL, upon the failure of any command in the queue.
+ TRUE, otherwise.
+ EXAMPLE
+ $mpdObject->QueueCommand(MPD_CMD_ADD,"myfile.mp3");
+ $mpdObject->QueueCommand(MPD_CMD_VOL,"+20");
+ $mpdObject->SendCommandQueue();
+
+
+
+RefreshInfo() -
+ Retrieves all object data from the MPD and stores it in each of the object
+ properties. Note: As of version 1.1, this is automatically called upon initial connection
+ to the MPD server; there is little need to use it.
+
+ RETURNS
+ TRUE, upon success
+ NULL, upon failure
+ EXAMPLE
+ $mpdObject->RefreshInfo();
+
+
+
+
+
diff --git a/modules/mpd/mpd-class-example.php b/modules/mpd/mpd-class-example.php
new file mode 100644
index 00000000..802153de
--- /dev/null
+++ b/modules/mpd/mpd-class-example.php
@@ -0,0 +1,144 @@
+<?php
+/*
+ * mpd-class-example.php - Example interface using mpd.class.php
+ * Version 1.2, released 05/05/2004
+ * Copyright (C) 2003-2004 Benjamin Carlisle (bcarlisle@24oz.com)
+ * http://mpd.24oz.com/ | http://www.musicpd.org/
+ *
+ * This program illustrates the basic commands and usage of the MPD class.
+ *
+ * *** PLEASE NOTE *** My intention in including this file is not to provide you with an
+ * out-of-the-box MPD jukebox, but instead to provide a general understanding of how I saw
+ * the class as being utilized. If you'd like to see more examples, please let me know. But
+ * this should provide you with a good starting point for your own program development.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+?>
+<HTML>
+<style type="text/css"><!-- .defaultText { font-family: Arial, Helvetica, sans-serif; font-size: 9pt; font-style: normal; font-weight: normal; color: #111111} .err { color: #DD3333 } --></style>
+<BODY class="defaultText">
+<?php
+ include('mpd.class.php');
+ $myMpd = new mpd('localhost',2100);
+
+ if ( $myMpd->connected == FALSE ) {
+ echo "Error Connecting: " . $myMpd->errStr;
+ } else {
+ switch ($_REQUEST[m]) {
+ case "add":
+ if ( is_null($myMpd->PLAdd($_REQUEST[filename])) ) echo "<SPAN CLASS=err>ERROR: " .$myMpd->errStr."</SPAN>";
+ break;
+ case "rem":
+ if ( is_null($myMpd->PLRemove($_REQUEST[id])) ) echo "<SPAN CLASS=err>ERROR: " .$myMpd->errStr."</SPAN>";
+ break;
+ case "setvol":
+ if ( is_null($myMpd->SetVolume($_REQUEST[vol])) ) echo "<SPAN CLASS=err>ERROR: " .$myMpd->errStr."</SPAN>";
+ break;
+ case "play":
+ if ( is_null($myMpd->Play()) ) echo "<SPAN CLASS=err>ERROR: " .$myMpd->errStr."</SPAN>";
+ break;
+ case "stop":
+ if ( is_null($myMpd->Stop()) ) echo "<SPAN CLASS=err>ERROR: " .$myMpd->errStr."</SPAN>";
+ break;
+ case "pause":
+ if ( is_null($myMpd->Pause()) ) echo "<SPAN CLASS=err>ERROR: " .$myMpd->errStr."</SPAN>";
+ break;
+ default:
+ break;
+ }
+?>
+<DIV ALIGN=CENTER>[ <A HREF="<?php echo $_SERVER[PHP_SELF] ?>">Refresh Page</A> ]</DIV>
+<HR>
+<B>Connected to MPD Version <?php echo $myMpd->mpd_version ?> at <?php echo $myMpd->host ?>:<?php echo $myMpd->port ?></B><BR>
+State:
+<?php
+ switch ($myMpd->state) {
+ case MPD_STATE_PLAYING: echo "MPD is Playing [<A HREF='".$_SERVER[PHP_SELF]."?m=pause'>Pause</A>] [<A HREF='".$_SERVER[PHP_SELF]."?m=stop'>Stop</A>]"; break;
+ case MPD_STATE_PAUSED: echo "MPD is Paused [<A HREF='".$_SERVER[PHP_SELF]."?m=pause'>Unpause</A>]"; break;
+ case MPD_STATE_STOPPED: echo "MPD is Stopped [<A HREF='".$_SERVER[PHP_SELF]."?m=play'>Play</A>]"; break;
+ default: echo "(Unknown State!)"; break;
+ }
+?>
+<BR>
+Volume: <?php echo $myMpd->volume ?> [ <A HREF='<?php echo $_SERVER[PHP_SELF] ?>?m=setvol&vol=0'>0</A> | <A HREF='<?php echo $_SERVER[PHP_SELF] ?>?m=setvol&vol=25'>25</A> | <A HREF='<?php echo $_SERVER[PHP_SELF] ?>?m=setvol&vol=75'>75</A> | <A HREF='<?php echo $_SERVER[PHP_SELF] ?>?m=setvol&vol=100'>100</A> ]<BR>
+Uptime: <?php echo secToTimeStr($myMpd->uptime) ?><BR>
+Playtime: <?php echo secToTimeStr($myMpd->playtime) ?><BR>
+
+<?php if ( $myMpd->state == MPD_STATE_PLAYING or $myMpd->state == MPD_STATE_PAUSED ) { ?>
+ Currently Playing: <?php echo $myMpd->playlist[$myMpd->current_track_id]['Artist']." - ".$myMpd->playlist[$myMpd->current_track_id]['Title'] ?><BR>
+ Track Position: <?php echo $myMpd->current_track_position."/".$myMpd->current_track_length." (".(round(($myMpd->current_track_position/$myMpd->current_track_length),2)*100)."%)" ?><BR>
+ Playlist Position: <?php echo ($myMpd->current_track_id+1)."/".$myMpd->playlist_count." (".(round((($myMpd->current_track_id+1)/$myMpd->playlist_count),2)*100)."%)" ?><BR>
+<?php } ?>
+<HR>
+
+<B>Playlist - Total: <?php echo $myMpd->playlist_count ?> tracks (Click to Remove)</B><BR>
+<?php
+ if ( is_null($myMpd->playlist) ) echo "ERROR: " .$myMpd->errStr."\n";
+ else {
+ foreach ($myMpd->playlist as $id => $entry) {
+ echo ( $id == $myMpd->current_track_id ? "<B>" : "" ) . ($id+1) . ". <A HREF='".$_SERVER[PHP_SELF]."?m=rem&id=".$id."'>".$entry['Artist']." - ".$entry['Title']."</A>".( $id == $myMpd->current_track_id ? "</B>" : "" )."<BR>\n";
+ }
+ }
+?>
+<HR>
+<B>Sample Search for the String 'U2' (Click to Add to Playlist)</B><BR>
+<?php
+ $sl = $myMpd->Search(MPD_SEARCH_ARTIST,'U2');
+ if ( is_null($sl) ) echo "ERROR: " .$myMpd->errStr."\n";
+ else {
+ foreach ($sl as $id => $entry) {
+ echo ($id+1) . ": <A HREF='".$_SERVER[PHP_SELF]."?m=add&filename=".urlencode($entry['file'])."'>".$entry['Artist']." - ".$entry['Title']."</A><BR>\n";
+ }
+ }
+ if ( count($sl) == 0 ) echo "<I>No results returned from search.</I>";
+
+
+ // Example of how you would use Bulk Add features of MPD
+ // $myarray = array();
+ // $myarray[0] = "ACDC - Thunderstruck.mp3";
+ // $myarray[1] = "ACDC - Back In Black.mp3";
+ // $myarray[2] = "ACDC - Hells Bells.mp3";
+
+ // if ( is_null($myMpd->PLAddBulk($myarray)) ) echo "ERROR: ".$myMpd->errStr."\n";
+?>
+<HR>
+<B>Artist List</B><BR>
+<?php
+ if ( is_null($ar = $myMpd->GetArtists()) ) echo "ERROR: " .$myMpd->errStr."\n";
+ else {
+ while(list($key, $value) = each($ar) ) {
+ echo ($key+1) . ". " . $value . "<BR>";
+ }
+ }
+
+ $myMpd->Disconnect();
+ }
+
+ // ---------------------------------------------------------------------------------
+ // Used to make number of seconds perty.
+ function secToTimeStr($secs) {
+ $days = ($secs%604800)/86400;
+ $hours = (($secs%604800)%86400)/3600;
+ $minutes = ((($secs%604800)%86400)%3600)/60;
+ $seconds = (((($secs%604800)%86400)%3600)%60);
+ if (round($days)) $timestring .= round($days)."d ";
+ if (round($hours)) $timestring .= round($hours)."h ";
+ if (round($minutes)) $timestring .= round($minutes)."m";
+ if (!round($minutes)&&!round($hours)&&!round($days)) $timestring.=" ".round($seconds)."s";
+ return $timestring;
+ } // --------------------------------------------------------------------------------
+?>
+</BODY></HTML>
diff --git a/modules/mpd/mpd.class.php b/modules/mpd/mpd.class.php
new file mode 100644
index 00000000..ed324ba3
--- /dev/null
+++ b/modules/mpd/mpd.class.php
@@ -0,0 +1,968 @@
+<?php
+/*
+ * mpd.class.php - PHP Object Interface to the MPD Music Player Daemon
+ * Version 1.2, Released 05/05/2004
+ * Copyright (C) 2003-2004 Benjamin Carlisle (bcarlisle@24oz.com)
+ * http://mpd.24oz.com/ | http://www.musicpd.org/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+// Create common command definitions for MPD to use
+define("MPD_CMD_STATUS", "status");
+define("MPD_CMD_STATISTICS", "stats");
+define("MPD_CMD_VOLUME", "volume");
+define("MPD_CMD_SETVOL", "setvol");
+define("MPD_CMD_PLAY", "play");
+define("MPD_CMD_STOP", "stop");
+define("MPD_CMD_PAUSE", "pause");
+define("MPD_CMD_NEXT", "next");
+define("MPD_CMD_PREV", "previous");
+define("MPD_CMD_PLLIST", "playlistinfo");
+define("MPD_CMD_PLADD", "add");
+define("MPD_CMD_PLREMOVE", "delete");
+define("MPD_CMD_PLCLEAR", "clear");
+define("MPD_CMD_PLSHUFFLE", "shuffle");
+define("MPD_CMD_PLLOAD", "load");
+define("MPD_CMD_PLSAVE", "save");
+define("MPD_CMD_KILL", "kill");
+define("MPD_CMD_REFRESH", "update");
+define("MPD_CMD_REPEAT", "repeat");
+define("MPD_CMD_LSDIR", "lsinfo");
+define("MPD_CMD_SEARCH", "search");
+define("MPD_CMD_START_BULK", "command_list_begin");
+define("MPD_CMD_END_BULK", "command_list_end");
+define("MPD_CMD_FIND", "find");
+define("MPD_CMD_RANDOM", "random");
+define("MPD_CMD_SEEK", "seek");
+define("MPD_CMD_PLSWAPTRACK", "swap");
+define("MPD_CMD_PLMOVETRACK", "move");
+define("MPD_CMD_PASSWORD", "password");
+define("MPD_CMD_TABLE", "list");
+
+// Predefined MPD Response messages
+define("MPD_RESPONSE_ERR", "ACK");
+define("MPD_RESPONSE_OK", "OK");
+
+// MPD State Constants
+define("MPD_STATE_PLAYING", "play");
+define("MPD_STATE_STOPPED", "stop");
+define("MPD_STATE_PAUSED", "pause");
+
+// MPD Searching Constants
+define("MPD_SEARCH_ARTIST", "artist");
+define("MPD_SEARCH_TITLE", "title");
+define("MPD_SEARCH_ALBUM", "album");
+
+// MPD Cache Tables
+define("MPD_TBL_ARTIST","artist");
+define("MPD_TBL_ALBUM","album");
+
+class mpd {
+ // TCP/Connection variables
+ var $host;
+ var $port;
+ var $password;
+
+ var $mpd_sock = NULL;
+ var $connected = FALSE;
+
+ // MPD Status variables
+ var $mpd_version = "(unknown)";
+
+ var $state;
+ var $current_track_position;
+ var $current_track_length;
+ var $current_track_id;
+ var $volume;
+ var $repeat;
+ var $random;
+
+ var $uptime;
+ var $playtime;
+ var $db_last_refreshed;
+ var $num_songs_played;
+ var $playlist_count;
+
+ var $num_artists;
+ var $num_albums;
+ var $num_songs;
+
+ var $playlist = array();
+
+ // Misc Other Vars
+ var $mpd_class_version = "1.2";
+
+ var $debugging = FALSE; // Set to TRUE to turn extended debugging on.
+ var $errStr = ""; // Used for maintaining information about the last error message
+
+ var $command_queue; // The list of commands for bulk command sending
+
+ // =================== BEGIN OBJECT METHODS ================
+
+ /* mpd() : Constructor
+ *
+ * Builds the MPD object, connects to the server, and refreshes all local object properties.
+ */
+ function mpd($srv,$port,$pwd = NULL) {
+ $this->host = $srv;
+ $this->port = $port;
+ $this->password = $pwd;
+
+ $resp = $this->Connect();
+ if ( is_null($resp) ) {
+ $this->errStr = "Could not connect";
+ return;
+ } else {
+ list ( $this->mpd_version ) = sscanf($resp, MPD_RESPONSE_OK . " MPD %s\n");
+ if ( ! is_null($pwd) ) {
+ if ( is_null($this->SendCommand(MPD_CMD_PASSWORD,$pwd)) ) {
+ $this->connected = FALSE;
+ return; // bad password or command
+ }
+ if ( is_null($this->RefreshInfo()) ) { // no read access -- might as well be disconnected!
+ $this->connected = FALSE;
+ $this->errStr = "Password supplied does not have read access";
+ return;
+ }
+ } else {
+ if ( is_null($this->RefreshInfo()) ) { // no read access -- might as well be disconnected!
+ $this->connected = FALSE;
+ $this->errStr = "Password required to access server";
+ return;
+ }
+ }
+ }
+ }
+
+ /* Connect()
+ *
+ * Connects to the MPD server.
+ *
+ * NOTE: This is called automatically upon object instantiation; you should not need to call this directly.
+ */
+ function Connect() {
+ if ( $this->debugging ) echo "mpd->Connect() / host: ".$this->host.", port: ".$this->port."\n";
+ $this->mpd_sock = fsockopen($this->host,$this->port,$errNo,$errStr,10);
+ if (!$this->mpd_sock) {
+ $this->errStr = "Socket Error: $errStr ($errNo)";
+ return NULL;
+ } else {
+ while(!feof($this->mpd_sock)) {
+ $response = fgets($this->mpd_sock,1024);
+ if (strncmp(MPD_RESPONSE_OK,$response,strlen(MPD_RESPONSE_OK)) == 0) {
+ $this->connected = TRUE;
+ return $response;
+ break;
+ }
+ if (strncmp(MPD_RESPONSE_ERR,$response,strlen(MPD_RESPONSE_ERR)) == 0) {
+ $this->errStr = "Server responded with: $response";
+ return NULL;
+ }
+ }
+ // Generic response
+ $this->errStr = "Connection not available";
+ return NULL;
+ }
+ }
+
+ /* SendCommand()
+ *
+ * Sends a generic command to the MPD server. Several command constants are pre-defined for
+ * use (see MPD_CMD_* constant definitions above).
+ */
+ function SendCommand($cmdStr,$arg1 = "",$arg2 = "") {
+ if ( $this->debugging ) echo "mpd->SendCommand() / cmd: ".$cmdStr.", args: ".$arg1." ".$arg2."\n";
+ if ( ! $this->connected ) {
+ echo "mpd->SendCommand() / Error: Not connected\n";
+ } else {
+ // Clear out the error String
+ $this->errStr = "";
+ $respStr = "";
+
+ // Check the command compatibility:
+ if ( ! $this->_checkCompatibility($cmdStr) ) {
+ return NULL;
+ }
+
+ if (strlen($arg1) > 0) $cmdStr .= " \"$arg1\"";
+ if (strlen($arg2) > 0) $cmdStr .= " \"$arg2\"";
+ fputs($this->mpd_sock,"$cmdStr\n");
+ while(!feof($this->mpd_sock)) {
+ $response = fgets($this->mpd_sock,1024);
+
+ // An OK signals the end of transmission -- we'll ignore it
+ if (strncmp(MPD_RESPONSE_OK,$response,strlen(MPD_RESPONSE_OK)) == 0) {
+ break;
+ }
+
+ // An ERR signals the end of transmission with an error! Let's grab the single-line message.
+ if (strncmp(MPD_RESPONSE_ERR,$response,strlen(MPD_RESPONSE_ERR)) == 0) {
+ list ( $junk, $errTmp ) = split(MPD_RESPONSE_ERR . " ",$response );
+ $this->errStr = strtok($errTmp,"\n");
+ }
+
+ if ( strlen($this->errStr) > 0 ) {
+ return NULL;
+ }
+
+ // Build the response string
+ $respStr .= $response;
+ }
+ if ( $this->debugging ) echo "mpd->SendCommand() / response: '".$respStr."'\n";
+ }
+ return $respStr;
+ }
+
+ /* QueueCommand()
+ *
+ * Queues a generic command for later sending to the MPD server. The CommandQueue can hold
+ * as many commands as needed, and are sent all at once, in the order they are queued, using
+ * the SendCommandQueue() method. The syntax for queueing commands is identical to SendCommand().
+ */
+ function QueueCommand($cmdStr,$arg1 = "",$arg2 = "") {
+ if ( $this->debugging ) echo "mpd->QueueCommand() / cmd: ".$cmdStr.", args: ".$arg1." ".$arg2."\n";
+ if ( ! $this->connected ) {
+ echo "mpd->QueueCommand() / Error: Not connected\n";
+ return NULL;
+ } else {
+ if ( strlen($this->command_queue) == 0 ) {
+ $this->command_queue = MPD_CMD_START_BULK . "\n";
+ }
+ if (strlen($arg1) > 0) $cmdStr .= " \"$arg1\"";
+ if (strlen($arg2) > 0) $cmdStr .= " \"$arg2\"";
+
+ $this->command_queue .= $cmdStr ."\n";
+
+ if ( $this->debugging ) echo "mpd->QueueCommand() / return\n";
+ }
+ return TRUE;
+ }
+
+ /* SendCommandQueue()
+ *
+ * Sends all commands in the Command Queue to the MPD server. See also QueueCommand().
+ */
+ function SendCommandQueue() {
+ if ( $this->debugging ) echo "mpd->SendCommandQueue()\n";
+ if ( ! $this->connected ) {
+ echo "mpd->SendCommandQueue() / Error: Not connected\n";
+ return NULL;
+ } else {
+ $this->command_queue .= MPD_CMD_END_BULK . "\n";
+ if ( is_null($respStr = $this->SendCommand($this->command_queue)) ) {
+ return NULL;
+ } else {
+ $this->command_queue = NULL;
+ if ( $this->debugging ) echo "mpd->SendCommandQueue() / response: '".$respStr."'\n";
+ }
+ }
+ return $respStr;
+ }
+
+ /* AdjustVolume()
+ *
+ * Adjusts the mixer volume on the MPD by <modifier>, which can be a positive (volume increase),
+ * or negative (volume decrease) value.
+ */
+ function AdjustVolume($modifier) {
+ if ( $this->debugging ) echo "mpd->AdjustVolume()\n";
+ if ( ! is_numeric($modifier) ) {
+ $this->errStr = "AdjustVolume() : argument 1 must be a numeric value";
+ return NULL;
+ }
+
+ $this->RefreshInfo();
+ $newVol = $this->volume + $modifier;
+ $ret = $this->SetVolume($newVol);
+
+ if ( $this->debugging ) echo "mpd->AdjustVolume() / return\n";
+ return $ret;
+ }
+
+ /* SetVolume()
+ *
+ * Sets the mixer volume to <newVol>, which should be between 1 - 100.
+ */
+ function SetVolume($newVol) {
+ if ( $this->debugging ) echo "mpd->SetVolume()\n";
+ if ( ! is_numeric($newVol) ) {
+ $this->errStr = "SetVolume() : argument 1 must be a numeric value";
+ return NULL;
+ }
+
+ // Forcibly prevent out of range errors
+ if ( $newVol < 0 ) $newVol = 0;
+ if ( $newVol > 100 ) $newVol = 100;
+
+ // If we're not compatible with SETVOL, we'll try adjusting using VOLUME
+ if ( $this->_checkCompatibility(MPD_CMD_SETVOL) ) {
+ if ( ! is_null($ret = $this->SendCommand(MPD_CMD_SETVOL,$newVol))) $this->volume = $newVol;
+ } else {
+ $this->RefreshInfo(); // Get the latest volume
+ if ( is_null($this->volume) ) {
+ return NULL;
+ } else {
+ $modifier = ( $newVol - $this->volume );
+ if ( ! is_null($ret = $this->SendCommand(MPD_CMD_VOLUME,$modifier))) $this->volume = $newVol;
+ }
+ }
+
+ if ( $this->debugging ) echo "mpd->SetVolume() / return\n";
+ return $ret;
+ }
+
+ /* GetDir()
+ *
+ * Retrieves a database directory listing of the <dir> directory and places the results into
+ * a multidimensional array. If no directory is specified, the directory listing is at the
+ * base of the MPD music path.
+ */
+ function GetDir($dir = "") {
+ if ( $this->debugging ) echo "mpd->GetDir()\n";
+ $resp = $this->SendCommand(MPD_CMD_LSDIR,$dir);
+ $dirlist = $this->_parseFileListResponse($resp);
+ if ( $this->debugging ) echo "mpd->GetDir() / return ".print_r($dirlist)."\n";
+ return $dirlist;
+ }
+
+ /* PLAdd()
+ *
+ * Adds each track listed in a single-dimensional <trackArray>, which contains filenames
+ * of tracks to add, to the end of the playlist. This is used to add many, many tracks to
+ * the playlist in one swoop.
+ */
+ function PLAddBulk($trackArray) {
+ if ( $this->debugging ) echo "mpd->PLAddBulk()\n";
+ $num_files = count($trackArray);
+ for ( $i = 0; $i < $num_files; $i++ ) {
+ $this->QueueCommand(MPD_CMD_PLADD,$trackArray[$i]);
+ }
+ $resp = $this->SendCommandQueue();
+ $this->RefreshInfo();
+ if ( $this->debugging ) echo "mpd->PLAddBulk() / return\n";
+ return $resp;
+ }
+
+ /* PLAdd()
+ *
+ * Adds the file <file> to the end of the playlist. <file> must be a track in the MPD database.
+ */
+ function PLAdd($fileName) {
+ if ( $this->debugging ) echo "mpd->PLAdd()\n";
+ if ( ! is_null($resp = $this->SendCommand(MPD_CMD_PLADD,$fileName))) $this->RefreshInfo();
+ if ( $this->debugging ) echo "mpd->PLAdd() / return\n";
+ return $resp;
+ }
+
+ /* PLMoveTrack()
+ *
+ * Moves track number <origPos> to position <newPos> in the playlist. This is used to reorder
+ * the songs in the playlist.
+ */
+ function PLMoveTrack($origPos, $newPos) {
+ if ( $this->debugging ) echo "mpd->PLMoveTrack()\n";
+ if ( ! is_numeric($origPos) ) {
+ $this->errStr = "PLMoveTrack(): argument 1 must be numeric";
+ return NULL;
+ }
+ if ( $origPos < 0 or $origPos > $this->playlist_count ) {
+ $this->errStr = "PLMoveTrack(): argument 1 out of range";
+ return NULL;
+ }
+ if ( $newPos < 0 ) $newPos = 0;
+ if ( $newPos > $this->playlist_count ) $newPos = $this->playlist_count;
+
+ if ( ! is_null($resp = $this->SendCommand(MPD_CMD_PLMOVETRACK,$origPos,$newPos))) $this->RefreshInfo();
+ if ( $this->debugging ) echo "mpd->PLMoveTrack() / return\n";
+ return $resp;
+ }
+
+ /* PLShuffle()
+ *
+ * Randomly reorders the songs in the playlist.
+ */
+ function PLShuffle() {
+ if ( $this->debugging ) echo "mpd->PLShuffle()\n";
+ if ( ! is_null($resp = $this->SendCommand(MPD_CMD_PLSHUFFLE))) $this->RefreshInfo();
+ if ( $this->debugging ) echo "mpd->PLShuffle() / return\n";
+ return $resp;
+ }
+
+ /* PLLoad()
+ *
+ * Retrieves the playlist from <file>.m3u and loads it into the current playlist.
+ */
+ function PLLoad($file) {
+ if ( $this->debugging ) echo "mpd->PLLoad()\n";
+ if ( ! is_null($resp = $this->SendCommand(MPD_CMD_PLLOAD,$file))) $this->RefreshInfo();
+ if ( $this->debugging ) echo "mpd->PLLoad() / return\n";
+ return $resp;
+ }
+
+ /* PLSave()
+ *
+ * Saves the playlist to <file>.m3u for later retrieval. The file is saved in the MPD playlist
+ * directory.
+ */
+ function PLSave($file) {
+ if ( $this->debugging ) echo "mpd->PLSave()\n";
+ $resp = $this->SendCommand(MPD_CMD_PLSAVE,$file);
+ if ( $this->debugging ) echo "mpd->PLSave() / return\n";
+ return $resp;
+ }
+
+ /* PLClear()
+ *
+ * Empties the playlist.
+ */
+ function PLClear() {
+ if ( $this->debugging ) echo "mpd->PLClear()\n";
+ if ( ! is_null($resp = $this->SendCommand(MPD_CMD_PLCLEAR))) $this->RefreshInfo();
+ if ( $this->debugging ) echo "mpd->PLClear() / return\n";
+ return $resp;
+ }
+
+ /* PLRemove()
+ *
+ * Removes track <id> from the playlist.
+ */
+ function PLRemove($id) {
+ if ( $this->debugging ) echo "mpd->PLRemove()\n";
+ if ( ! is_numeric($id) ) {
+ $this->errStr = "PLRemove() : argument 1 must be a numeric value";
+ return NULL;
+ }
+ if ( ! is_null($resp = $this->SendCommand(MPD_CMD_PLREMOVE,$id))) $this->RefreshInfo();
+ if ( $this->debugging ) echo "mpd->PLRemove() / return\n";
+ return $resp;
+ }
+
+ /* SetRepeat()
+ *
+ * Enables 'loop' mode -- tells MPD continually loop the playlist. The <repVal> parameter
+ * is either 1 (on) or 0 (off).
+ */
+ function SetRepeat($repVal) {
+ if ( $this->debugging ) echo "mpd->SetRepeat()\n";
+ $rpt = $this->SendCommand(MPD_CMD_REPEAT,$repVal);
+ $this->repeat = $repVal;
+ if ( $this->debugging ) echo "mpd->SetRepeat() / return\n";
+ return $rpt;
+ }
+
+ /* SetRandom()
+ *
+ * Enables 'randomize' mode -- tells MPD to play songs in the playlist in random order. The
+ * <rndVal> parameter is either 1 (on) or 0 (off).
+ */
+ function SetRandom($rndVal) {
+ if ( $this->debugging ) echo "mpd->SetRandom()\n";
+ $resp = $this->SendCommand(MPD_CMD_RANDOM,$rndVal);
+ $this->random = $rndVal;
+ if ( $this->debugging ) echo "mpd->SetRandom() / return\n";
+ return $resp;
+ }
+
+ /* Shutdown()
+ *
+ * Shuts down the MPD server (aka sends the KILL command). This closes the current connection,
+ * and prevents future communication with the server.
+ */
+ function Shutdown() {
+ if ( $this->debugging ) echo "mpd->Shutdown()\n";
+ $resp = $this->SendCommand(MPD_CMD_SHUTDOWN);
+
+ $this->connected = FALSE;
+ unset($this->mpd_version);
+ unset($this->errStr);
+ unset($this->mpd_sock);
+
+ if ( $this->debugging ) echo "mpd->Shutdown() / return\n";
+ return $resp;
+ }
+
+ /* DBRefresh()
+ *
+ * Tells MPD to rescan the music directory for new tracks, and to refresh the Database. Tracks
+ * cannot be played unless they are in the MPD database.
+ */
+ function DBRefresh() {
+ if ( $this->debugging ) echo "mpd->DBRefresh()\n";
+ $resp = $this->SendCommand(MPD_CMD_REFRESH);
+
+ // Update local variables
+ $this->RefreshInfo();
+
+ if ( $this->debugging ) echo "mpd->DBRefresh() / return\n";
+ return $resp;
+ }
+
+ /* Play()
+ *
+ * Begins playing the songs in the MPD playlist.
+ */
+ function Play() {
+ if ( $this->debugging ) echo "mpd->Play()\n";
+ if ( ! is_null($rpt = $this->SendCommand(MPD_CMD_PLAY) )) $this->RefreshInfo();
+ if ( $this->debugging ) echo "mpd->Play() / return\n";
+ return $rpt;
+ }
+
+ /* Stop()
+ *
+ * Stops playing the MPD.
+ */
+ function Stop() {
+ if ( $this->debugging ) echo "mpd->Stop()\n";
+ if ( ! is_null($rpt = $this->SendCommand(MPD_CMD_STOP) )) $this->RefreshInfo();
+ if ( $this->debugging ) echo "mpd->Stop() / return\n";
+ return $rpt;
+ }
+
+ /* Pause()
+ *
+ * Toggles pausing on the MPD. Calling it once will pause the player, calling it again
+ * will unpause.
+ */
+ function Pause() {
+ if ( $this->debugging ) echo "mpd->Pause()\n";
+ if ( ! is_null($rpt = $this->SendCommand(MPD_CMD_PAUSE) )) $this->RefreshInfo();
+ if ( $this->debugging ) echo "mpd->Pause() / return\n";
+ return $rpt;
+ }
+
+ /* SeekTo()
+ *
+ * Skips directly to the <idx> song in the MPD playlist.
+ */
+ function SkipTo($idx) {
+ if ( $this->debugging ) echo "mpd->SkipTo()\n";
+ if ( ! is_numeric($idx) ) {
+ $this->errStr = "SkipTo() : argument 1 must be a numeric value";
+ return NULL;
+ }
+ if ( ! is_null($rpt = $this->SendCommand(MPD_CMD_PLAY,$idx))) $this->RefreshInfo();
+ if ( $this->debugging ) echo "mpd->SkipTo() / return\n";
+ return $idx;
+ }
+
+ /* SeekTo()
+ *
+ * Skips directly to a given position within a track in the MPD playlist. The <pos> argument,
+ * given in seconds, is the track position to locate. The <track> argument, if supplied is
+ * the track number in the playlist. If <track> is not specified, the current track is assumed.
+ */
+ function SeekTo($pos, $track = -1) {
+ if ( $this->debugging ) echo "mpd->SeekTo()\n";
+ if ( ! is_numeric($pos) ) {
+ $this->errStr = "SeekTo() : argument 1 must be a numeric value";
+ return NULL;
+ }
+ if ( ! is_numeric($track) ) {
+ $this->errStr = "SeekTo() : argument 2 must be a numeric value";
+ return NULL;
+ }
+ if ( $track == -1 ) {
+ $track = $this->current_track_id;
+ }
+
+ if ( ! is_null($rpt = $this->SendCommand(MPD_CMD_SEEK,$track,$pos))) $this->RefreshInfo();
+ if ( $this->debugging ) echo "mpd->SeekTo() / return\n";
+ return $pos;
+ }
+
+ /* Next()
+ *
+ * Skips to the next song in the MPD playlist. If not playing, returns an error.
+ */
+ function Next() {
+ if ( $this->debugging ) echo "mpd->Next()\n";
+ if ( ! is_null($rpt = $this->SendCommand(MPD_CMD_NEXT))) $this->RefreshInfo();
+ if ( $this->debugging ) echo "mpd->Next() / return\n";
+ return $rpt;
+ }
+
+ /* Previous()
+ *
+ * Skips to the previous song in the MPD playlist. If not playing, returns an error.
+ */
+ function Previous() {
+ if ( $this->debugging ) echo "mpd->Previous()\n";
+ if ( ! is_null($rpt = $this->SendCommand(MPD_CMD_PREV))) $this->RefreshInfo();
+ if ( $this->debugging ) echo "mpd->Previous() / return\n";
+ return $rpt;
+ }
+
+ /* Search()
+ *
+ * Searches the MPD database. The search <type> should be one of the following:
+ * MPD_SEARCH_ARTIST, MPD_SEARCH_TITLE, MPD_SEARCH_ALBUM
+ * The search <string> is a case-insensitive locator string. Anything that contains
+ * <string> will be returned in the results.
+ */
+ function Search($type,$string) {
+ if ( $this->debugging ) echo "mpd->Search()\n";
+ if ( $type != MPD_SEARCH_ARTIST and
+ $type != MPD_SEARCH_ALBUM and
+ $type != MPD_SEARCH_TITLE ) {
+ $this->errStr = "mpd->Search(): invalid search type";
+ return NULL;
+ } else {
+ if ( is_null($resp = $this->SendCommand(MPD_CMD_SEARCH,$type,$string))) return NULL;
+ $searchlist = $this->_parseFileListResponse($resp);
+ }
+ if ( $this->debugging ) echo "mpd->Search() / return ".print_r($searchlist)."\n";
+ return $searchlist;
+ }
+
+ /* Find()
+ *
+ * Find() looks for exact matches in the MPD database. The find <type> should be one of
+ * the following:
+ * MPD_SEARCH_ARTIST, MPD_SEARCH_TITLE, MPD_SEARCH_ALBUM
+ * The find <string> is a case-insensitive locator string. Anything that exactly matches
+ * <string> will be returned in the results.
+ */
+ function Find($type,$string) {
+ if ( $this->debugging ) echo "mpd->Find()\n";
+ if ( $type != MPD_SEARCH_ARTIST and
+ $type != MPD_SEARCH_ALBUM and
+ $type != MPD_SEARCH_TITLE ) {
+ $this->errStr = "mpd->Find(): invalid find type";
+ return NULL;
+ } else {
+ if ( is_null($resp = $this->SendCommand(MPD_CMD_FIND,$type,$string))) return NULL;
+ $searchlist = $this->_parseFileListResponse($resp);
+ }
+ if ( $this->debugging ) echo "mpd->Find() / return ".print_r($searchlist)."\n";
+ return $searchlist;
+ }
+
+ /* Disconnect()
+ *
+ * Closes the connection to the MPD server.
+ */
+ function Disconnect() {
+ if ( $this->debugging ) echo "mpd->Disconnect()\n";
+ fclose($this->mpd_sock);
+
+ $this->connected = FALSE;
+ unset($this->mpd_version);
+ unset($this->errStr);
+ unset($this->mpd_sock);
+ }
+
+ /* GetArtists()
+ *
+ * Returns the list of artists in the database in an associative array.
+ */
+ function GetArtists() {
+ if ( $this->debugging ) echo "mpd->GetArtists()\n";
+ if ( is_null($resp = $this->SendCommand(MPD_CMD_TABLE, MPD_TBL_ARTIST))) return NULL;
+ $arArray = array();
+
+ $arLine = strtok($resp,"\n");
+ $arName = "";
+ $arCounter = -1;
+ while ( $arLine ) {
+ list ( $element, $value ) = split(": ",$arLine);
+ if ( $element == "Artist" ) {
+ $arCounter++;
+ $arName = $value;
+ $arArray[$arCounter] = $arName;
+ }
+
+ $arLine = strtok("\n");
+ }
+ if ( $this->debugging ) echo "mpd->GetArtists()\n";
+ return $arArray;
+ }
+
+ /* GetAlbums()
+ *
+ * Returns the list of albums in the database in an associative array. Optional parameter
+ * is an artist Name which will list all albums by a particular artist.
+ */
+ function GetAlbums( $ar = NULL) {
+ if ( $this->debugging ) echo "mpd->GetAlbums()\n";
+ if ( is_null($resp = $this->SendCommand(MPD_CMD_TABLE, MPD_TBL_ALBUM, $ar ))) return NULL;
+ $alArray = array();
+
+ $alLine = strtok($resp,"\n");
+ $alName = "";
+ $alCounter = -1;
+ while ( $alLine ) {
+ list ( $element, $value ) = split(": ",$alLine);
+ if ( $element == "Album" ) {
+ $alCounter++;
+ $alName = $value;
+ $alArray[$alCounter] = $alName;
+ }
+
+ $alLine = strtok("\n");
+ }
+ if ( $this->debugging ) echo "mpd->GetAlbums()\n";
+ return $alArray;
+ }
+
+ //*******************************************************************************//
+ //***************************** INTERNAL FUNCTIONS ******************************//
+ //*******************************************************************************//
+
+ /* _computeVersionValue()
+ *
+ * Computes a compatibility value from a version string
+ *
+ */
+ function _computeVersionValue($verStr) {
+ list ($ver_maj, $ver_min, $ver_rel ) = split("\.",$verStr);
+ return ( 100 * $ver_maj ) + ( 10 * $ver_min ) + ( $ver_rel );
+ }
+
+ /* _checkCompatibility()
+ *
+ * Check MPD command compatibility against our internal table. If there is no version
+ * listed in the table, allow it by default.
+ */
+ function _checkCompatibility($cmd) {
+ // Check minimum compatibility
+ $req_ver_low = $this->COMPATIBILITY_MIN_TBL[$cmd];
+ $req_ver_hi = $this->COMPATIBILITY_MAX_TBL[$cmd];
+
+ $mpd_ver = $this->_computeVersionValue($this->mpd_version);
+
+ if ( $req_ver_low ) {
+ $req_ver = $this->_computeVersionValue($req_ver_low);
+
+ if ( $mpd_ver < $req_ver ) {
+ $this->errStr = "Command '$cmd' is not compatible with this version of MPD, version ".$req_ver_low." required";
+ return FALSE;
+ }
+ }
+
+ // Check maxmum compatibility -- this will check for deprecations
+ if ( $req_ver_hi ) {
+ $req_ver = $this->_computeVersionValue($req_ver_hi);
+
+ if ( $mpd_ver > $req_ver ) {
+ $this->errStr = "Command '$cmd' has been deprecated in this version of MPD.";
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+ }
+
+ /* _parseFileListResponse()
+ *
+ * Builds a multidimensional array with MPD response lists.
+ *
+ * NOTE: This function is used internally within the class. It should not be used.
+ */
+ function _parseFileListResponse($resp) {
+ if ( is_null($resp) ) {
+ return NULL;
+ } else {
+ $plistArray = array();
+ $plistLine = strtok($resp,"\n");
+ $plistFile = "";
+ $plCounter = -1;
+ while ( $plistLine ) {
+ list ( $element, $value ) = split(": ",$plistLine);
+ if ( $element == "file" ) {
+ $plCounter++;
+ $plistFile = $value;
+ $plistArray[$plCounter]["file"] = $plistFile;
+ } else {
+ $plistArray[$plCounter][$element] = $value;
+ }
+
+ $plistLine = strtok("\n");
+ }
+ }
+ return $plistArray;
+ }
+
+ /* RefreshInfo()
+ *
+ * Updates all class properties with the values from the MPD server.
+ *
+ * NOTE: This function is automatically called upon Connect() as of v1.1.
+ */
+ function RefreshInfo() {
+ // Get the Server Statistics
+ $statStr = $this->SendCommand(MPD_CMD_STATISTICS);
+ if ( !$statStr ) {
+ return NULL;
+ } else {
+ $stats = array();
+ $statLine = strtok($statStr,"\n");
+ while ( $statLine ) {
+ list ( $element, $value ) = split(": ",$statLine);
+ $stats[$element] = $value;
+ $statLine = strtok("\n");
+ }
+ }
+
+ // Get the Server Status
+ $statusStr = $this->SendCommand(MPD_CMD_STATUS);
+ if ( ! $statusStr ) {
+ return NULL;
+ } else {
+ $status = array();
+ $statusLine = strtok($statusStr,"\n");
+ while ( $statusLine ) {
+ list ( $element, $value ) = split(": ",$statusLine);
+ $status[$element] = $value;
+ $statusLine = strtok("\n");
+ }
+ }
+
+ // Get the Playlist
+ $plStr = $this->SendCommand(MPD_CMD_PLLIST);
+ $this->playlist = $this->_parseFileListResponse($plStr);
+ $this->playlist_count = count($this->playlist);
+
+ // Set Misc Other Variables
+ $this->state = $status['state'];
+ if ( ($this->state == MPD_STATE_PLAYING) || ($this->state == MPD_STATE_PAUSED) ) {
+ $this->current_track_id = $status['song'];
+ list ($this->current_track_position, $this->current_track_length ) = split(":",$status['time']);
+ } else {
+ $this->current_track_id = -1;
+ $this->current_track_position = -1;
+ $this->current_track_length = -1;
+ }
+
+ $this->repeat = $status['repeat'];
+ $this->random = $status['random'];
+
+ $this->db_last_refreshed = $stats['db_update'];
+
+ $this->volume = $status['volume'];
+ $this->uptime = $stats['uptime'];
+ $this->playtime = $stats['playtime'];
+ $this->num_songs_played = $stats['songs_played'];
+ $this->num_artists = $stats['num_artists'];
+ $this->num_songs = $stats['num_songs'];
+ $this->num_albums = $stats['num_albums'];
+ return TRUE;
+ }
+
+ /* ------------------ DEPRECATED METHODS -------------------*/
+ /* GetStatistics()
+ *
+ * Retrieves the 'statistics' variables from the server and tosses them into an array.
+ *
+ * NOTE: This function really should not be used. Instead, use $this->[variable]. The function
+ * will most likely be deprecated in future releases.
+ */
+ function GetStatistics() {
+ if ( $this->debugging ) echo "mpd->GetStatistics()\n";
+ $stats = $this->SendCommand(MPD_CMD_STATISTICS);
+ if ( !$stats ) {
+ return NULL;
+ } else {
+ $statsArray = array();
+ $statsLine = strtok($stats,"\n");
+ while ( $statsLine ) {
+ list ( $element, $value ) = split(": ",$statsLine);
+ $statsArray[$element] = $value;
+ $statsLine = strtok("\n");
+ }
+ }
+ if ( $this->debugging ) echo "mpd->GetStatistics() / return: " . print_r($statsArray) ."\n";
+ return $statsArray;
+ }
+
+ /* GetStatus()
+ *
+ * Retrieves the 'status' variables from the server and tosses them into an array.
+ *
+ * NOTE: This function really should not be used. Instead, use $this->[variable]. The function
+ * will most likely be deprecated in future releases.
+ */
+ function GetStatus() {
+ if ( $this->debugging ) echo "mpd->GetStatus()\n";
+ $status = $this->SendCommand(MPD_CMD_STATUS);
+ if ( ! $status ) {
+ return NULL;
+ } else {
+ $statusArray = array();
+ $statusLine = strtok($status,"\n");
+ while ( $statusLine ) {
+ list ( $element, $value ) = split(": ",$statusLine);
+ $statusArray[$element] = $value;
+ $statusLine = strtok("\n");
+ }
+ }
+ if ( $this->debugging ) echo "mpd->GetStatus() / return: " . print_r($statusArray) ."\n";
+ return $statusArray;
+ }
+
+ /* GetVolume()
+ *
+ * Retrieves the mixer volume from the server.
+ *
+ * NOTE: This function really should not be used. Instead, use $this->volume. The function
+ * will most likely be deprecated in future releases.
+ */
+ function GetVolume() {
+ if ( $this->debugging ) echo "mpd->GetVolume()\n";
+ $volLine = $this->SendCommand(MPD_CMD_STATUS);
+ if ( ! $volLine ) {
+ return NULL;
+ } else {
+ list ($vol) = sscanf($volLine,"volume: %d");
+ }
+ if ( $this->debugging ) echo "mpd->GetVolume() / return: $vol\n";
+ return $vol;
+ }
+
+ /* GetPlaylist()
+ *
+ * Retrieves the playlist from the server and tosses it into a multidimensional array.
+ *
+ * NOTE: This function really should not be used. Instead, use $this->playlist. The function
+ * will most likely be deprecated in future releases.
+ */
+ function GetPlaylist() {
+ if ( $this->debugging ) echo "mpd->GetPlaylist()\n";
+ $resp = $this->SendCommand(MPD_CMD_PLLIST);
+ $playlist = $this->_parseFileListResponse($resp);
+ if ( $this->debugging ) echo "mpd->GetPlaylist() / return ".print_r($playlist)."\n";
+ return $playlist;
+ }
+
+ /* ----------------- Command compatibility tables --------------------- */
+ var $COMPATIBILITY_MIN_TBL = array(
+ MPD_CMD_SEEK => "0.9.1" ,
+ MPD_CMD_PLMOVE => "0.9.1" ,
+ MPD_CMD_RANDOM => "0.9.1" ,
+ MPD_CMD_PLSWAPTRACK => "0.9.1" ,
+ MPD_CMD_PLMOVETRACK => "0.9.1" ,
+ MPD_CMD_PASSWORD => "0.10.0" ,
+ MPD_CMD_SETVOL => "0.10.0"
+ );
+
+ var $COMPATIBILITY_MAX_TBL = array(
+ MPD_CMD_VOLUME => "0.10.0"
+ );
+
+} // ---------------------------- end of class ------------------------------
+
+
+?>