MphpD
v1.2.6
MphpD是音乐播放器守护程序的库。它允许您以简单且面向对象的方式从 PHP 应用程序中控制 MPD,同时还处理转义、解析、错误报告和所有其他痛苦的事情。
支持整个MPD协议!
警告
该库及其文档相当年轻,因此并不完美。
请在此处报告您遇到的任何错误或问题。谢谢。
您可以使用 Composer 安装此库:
composer require flofaber/ MphpD
然后自动加载它:
require_once __DIR__ . " /vendor/autoload.php " ;
或者只需下载它并将其包含在您的代码中,如下所示:
require_once __DIR__ . " / MphpD / MphpD .php " ;
创建一个新的MphpD实例:
use FloFaber MphpD MphpD ;
use FloFaber MphpD MPDException ;
$ MphpD = new MphpD ([
" host " => " 127.0.0.1 " ,
" port " => 6600 ,
" timeout " => 5
]);
并连接到 MPD
try {
$ MphpD -> connect ();
} catch ( MPDException $ e ){
echo $ e -> getMessage ();
return false ;
}
以下是您可以用它做什么的一些示例:
// get MPD's status like current song, volume, state, etc...
$ status = $ MphpD -> status ();
// if you only want to retrieve only one (or more) values
// you can pass it a list of keys.
$ state = $ MphpD -> status ([ " state " ]);
// clear the queue
$ MphpD -> queue ()-> clear ();
// load the first 10 songs of a playlist into the queue and exit on failure.
if (! $ MphpD -> playlist ( " some-playlist " )-> load ([ 0 , 10 ])){
echo $ MphpD -> get_last_error ()[ " message " ]; // prints "No such playlist"
return false ;
}
// shuffle the queue
$ MphpD -> queue ()-> shuffle ();
// adjust volume to 40%
$ MphpD -> player ()-> volume ( 40 );
// start playing
$ MphpD -> player ()-> play ();
有关更多信息,请查看文档。
sockets
。 MphpD进行套接字通信所需的 PHP 函数列表:
fgets
fputs
fread
stream_get_meta_data
stream_set_chunk_size
stream_set_timeout
stream_socket_client