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