maxi/php-mpd

此包的最新版本(dev-master)没有可用的许可信息。

dev-master 2020-03-01 20:36 UTC

This package is auto-updated.

Last update: 2024-09-29 05:29:44 UTC


README

PHP 音乐播放器守护进程(MPD)通信库。

此 PHP 类提供了与任何 MPD 服务器进行轻松交互的方法。您无需深入了解 MPD 就可以使用此类,只要您知道 MPD 服务器(IP、端口和密码)即可。此类允许您执行 MPD 服务器上的任何功能,并以易于管理的方式将信息返回给您,以便您在 Web 界面上使用这些信息。

有用资源
MPD 社区维基:http://mpd.wikia.com/wiki/MusicPlayerDaemonWiki
MPD 维基页面:http://en.wikipedia.org/wiki/MusicPlayerDaemon

安装

composer require maxi/php-mpd

快速使用示例

require_once 'vendor/autoload.php';

use Mpd\Mpd;

$mpd = new Mpd('localhost', 6600);
if ($mpd->get_connection_status()) {
	print_r($mpd->server_status());
} else {
	print_r($mpd->get_error());
}

API

/**
 * Sets consume state to STATE, STATE should be 0 or 1. 
 * When consume is activated, each song played is removed from playlist. 
 * 
 * @param integer $state The consume state
 * @return boolean Status of the command
 */
consume($state)

/**
 * Sets crossfading between songs.
 * 
 * @param integer $seconds Crossfade seconds
 * @return boolean Status of the command
 */
xfade($seconds)

/**
 * Sets random state to STATE, STATE should be 0 or 1.
 * 
 * @param integer $state 0 = no and 1 = yes
 * @return boolean Status of the command
 */
random($state)

/**
 * Sets repeat state to STATE, STATE should be 0 or 1.
 * 
 * @param integer $state 0 = no and 1 = yes
 * @return boolean Status of the command
 */
repeat($state)

/**
 * Sets volume to VOL, the range of volume is 0-100.
 * 
 * @param integer $vol The new volume
 * @return boolean Status of the command
 */
setvol($vol)

/**
 * Adjusts the volume up or down depending if the modifier is positive or negative
 * 
 * @param integer $mod Volume modification
 * @return boolean Status of the command
 */
adjust_vol($mod)

/**
 * Sets single state to STATE, STATE should be 0 or 1. When single is activated, playback 
 * is stopped after current song, or song is repeated if the 'repeat' mode is enabled. 
 * 
 * @param integer $state Activate or deactivate single
 * @return boolean Status of the command
 */
single($state)

/**
 * Plays next song in the playlist.
 * 
 * @return boolean Status of the command
 */
next()

/**
 * Plays previous song in the playlist.
 * 
 * @return boolean Status of the command
 */
prev()

/**
 * Toggles pause/resumes playing, PAUSE is 0 or 1. 
 * 
 * @param integer $pause 0 = play and 1 = pause
 * @return boolean Status of the command
 */
pause($pause)

/**
 * Stops playing.
 * 
 * @return boolean Status of the command
 */
stop()

/**
 * Begins playing the playlist at song number SONGPOS.
 * 
 * @param integer $song_pos The song position in playlist
 * @return boolean Status of the command
 */
play($song_pos)

/**
 * Begins playing the playlist at song SONGID. 
 * 
 * @param integer $id The song ID
 * @return boolean Status of the command
 */
play_id($id)

/**
 * Seeks to the position TIME (in seconds) of entry SONGPOS in the playlist.
 * 
 * @param integer $song_pos The song position in playlist
 * @param integer $time Position time in seconds
 * @return boolean Status of the command
 */
seek($song_pos, $time)

/**
 * Seeks to the position TIME (in seconds) of song SONGID.
 * 
 * @param integer $song_id ID of the song
 * @param integer $time Position time in seconds
 * @return boolean Status of the command
 */
seek_id($song_id, $time)

/**
 * Adds the file URI to the playlist (directories add recursively). URI can also be a single file.
 * 
 * @param string $uri The file or dir to add
 * @return boolean Status of the command
 */
playlist_add($uri)

 /**
 * Adds a song to the playlist (non-recursive) and returns the song id.
 * URI is always a single file or URL. For example:
 * addid "foo.mp3"
 * Id: 999
 * OK
 * 
 * @param string $uri The file or dir to add
 * @param integer $pos Position in the playlist
 * @return boolean Status of the command
 */
playlist_add_id($uri, $pos)

/**
 * Clears the current playlist. 
 * 
 * @return boolean Status of the command
 */
playlist_clear()

/**
 * Deletes the song SONGID from the playlist
 * 
 * @param integer $id ID to remove
 * @return boolean Status of the command
 */
playlist_remove($id)

/**
 * Moves the song at FROM to TO in the playlist.
 * 
 * @param integer $from From playlist position
 * @param integer $to To playlist position
 * @return boolean Status of the command
 */
playlist_move($from, $to)

/**
 * Moves the range of songs at START:END to TO in the playlist.
 * 
 * @param integer $start Start position
 * @param integer $end End position
 * @param integer $to New position
 * @return boolean Status of the command
 */
playlist_move_multi($start, $end, $to)

/**
 * Moves the song with FROM (songid) to TO (playlist index) in the playlist. 
 * If TO is negative, it is relative to the current song in the playlist (if there is one). 
 * 
 * @param integer $from From song id
 * @param integer $to To playlist index
 * @return boolean Status of the command
 */
playlist_move_id($from, $to)

/**
 * Shuffles the current playlist.
 * 
 * @return boolean Status of the command
 */
playlist_shuffle()

/**
 * Lists the contents of the directory URI.
 * 
 * @param string $uri The dir to display, default is root dir
 * @return boolean|array Returns false if command failed and an array containing the dirlist and other stuffs on success ;)
 */
dir_list($uri = '')

/**
 * List all genres
 * 
 * @return boolean|array Returns false if command failed and an array containing the result on success
 */
list_genres()

/**
 * List all artists
 * 
 * @return boolean|array Returns false if command failed and an array containing the result on success
 */
list_artists()

/**
 * List all albums
 * 
 * @return boolean|array Returns false if command failed and an array containing the result on success
 */
list_albums()

/**
 * Searches for any song that contains WHAT. The search WHAT is not case sensitive.
 * TYPE can be any tag supported by MPD, or one of the two special parameters — 
 * file to search by full path (relative to database root), and any to match against all available tags
 * 
 * @param string $type Type to search for
 * @param string $what case insensitive search string
 * @return boolean|array Returns false if command failed and an array containing the result on success
 */
search($type, $what)

/**
 * Counts the number of songs and their total playtime in the db matching WHAT exactly.
 * 
 * @param string $type Type to search for
 * @param string $what case sensitive search string
 * @return boolean|array Returns false if command failed and an array containing the result on success
 */
count($type, $what)

/**
 * Updates the music database: find new files, remove deleted files, update modified files.
 * URI is a particular directory or song/file to update. If you do not specify it, everything is updated.
 * 
 * @param string $uri (Optional) If URI is give database only updates files in that URI
 * @return boolean|array Returns false if command fails and returns updating_db: JOBID where JOBID is a positive number identifying the update job on success
 */
update_db($uri = '')

/**
 * Displays the song info of the current song (same song that is identified in status).
 * 
 * @return boolean|array Returns false on failure and current song on success
 */
current_song()

/**
 * Displays a list of all songs in the playlist.
 * 
 * @return array Returns an array containing the songs in the playlist
 */
playlist()

/**
 * Reports the current status of the player and the volume level.
 * 
 * @return array Returns and array containing the status
 */
server_status()

/**
 * Displays statistics.
 * 
 * @return array Returns an array containing the statistics
 */
server_stats()

/**
 * Prints a list of the playlist directory.
 * 
 * @return boolean|array Returns false on failure and playlists on success 
 */
playlists()

/**
 * Lists the songs with metadata in the playlist. Playlist plugins are supported. 
 * 
 * @param string $playlist Name of the playlist to display
 * @return boolean|array Returns false on failure and playlist info on success
 */
playlistinfo($playlist)

/**
 * Loads the playlist into the current queue. Playlist plugins are supported. 
 * 
 * @param string $playlist Playlist to load
 * @return boolean Returns false on failure and true on success
 */
load_playlist($playlist)

/**
 * Adds URI to the playlist NAME.m3u.
 * NAME.m3u will be created if it does not exist.
 * 
 * @param string $playlist Playlist to add to
 * @param string $uri URI to add
 * @return boolean Returns false on failure and true on success
 */
add_to_playlist($playlist, $uri)

/**
 * Clears the playlist NAME.m3u.
 * 
 * @param string $playlist Playlist to clear
 * @return boolean Returns false on failure and true on success
 */
clear_playlist($playlist)

/**
 * Deletes SONGPOS from the playlist NAME.m3u
 * 
 * @param string $playlist Playlist to remove from
 * @param integer $song_pos Position of the song to remove
 * @return boolean Returns false on failure and true on success
 */
remove_from_playlist($playlist, $song_pos)

/**
 * Moves SONGID in the playlist NAME.m3u to the position SONGPOS.
 * 
 * @param string $playlist The playlist to interact with
 * @param integer $song_id I of the song to move
 * @param integer $song_pos Position of the new position in the playlist
 * @return boolean Returns false on failure and true on success
 */
move_song_in_playlist($playlist, $song_id, $song_pos)

/**
 * Renames the playlist NAME.m3u to NEW_NAME.m3u.
 * 
 * @param string $playlist Playlist to rename
 * @param strnig $new_name New name of playlist
 * @return boolean Returns false on failure and true on success
 */
rename_playlist($playlist, $new_name)

/**
 * Removes the playlist NAME.m3u from the playlist directory.
 * 
 * @param string $playlist Playlist to remove
 * @return boolean Returns false on failure and true on success
 */
remove_playlist($playlist)

/**
 * Saves the current playlist to NAME.m3u in the playlist directory.
 * 
 * @param string $playlist Name of the new playlist
 * @return boolean Returns false on failure and true on success
 */
save_playlist($playlist)

/**
 * Closes the connection to MPD.
 * 
 * @return boolean Returns false on failure and true on success
 */
close()

/**
 * Kills MPD.
 * 
 * @return boolean Returns false on failure and true on success
 */
kill()

/**
 * Send a command to the MPD server.
 * 
 * @param string $cmd The command to send
 * @param array $args An array with the command arguments
 * @return boolean|string Returns false if the command fails else returns the command result from the MPD server
 */
cmd($cmd, $args = array())

/**
 * Updates the object variables.
 * 
 * @return boolean Returns false if something went wrong else returns true
 */
update()

/**
 * Get the an array of error messages that has been collected since the object was instantiated.
 * 
 * @return array Returns an array with error messages
 */
get_error()

/**
 * Get the MPD connection status.
 * 
 * @return boolean Returns true if connected to MPD server, else returns false
 */
get_connection_status()

/**
 * Get the MPD version.
 * 
 * @return string Returns the version of the MPD
 */
get_version()

/**
 * Get the current debug log.
 * 
 * @return array Returns the debug log
 */
get_debug_log()

/**
 * Get the MPD class version.
 * 
 * @return string Returns the currenct version of this MPD class
 */
get_php_mpd_version()