MphpD ist eine Bibliothek für den Music Player Daemon. Damit können Sie MPD auf einfache und objektorientierte Weise aus Ihrer PHP-Anwendung heraus steuern und sich gleichzeitig um Escape, Parsing, Fehlerberichte und all die anderen lästigen Dinge kümmern.
Das gesamte MPD-Protokoll wird unterstützt!
Warnung
Diese Bibliothek und ihre Dokumentation sind noch recht jung und daher nicht perfekt.
Bitte melden Sie hier alle Fehler oder Probleme, auf die Sie stoßen. Danke.
Sie können diese Bibliothek entweder mit Composer installieren:
composer require flofaber/ MphpD
und dann automatisch laden:
require_once __DIR__ . " /vendor/autoload.php " ;
oder indem Sie es einfach herunterladen und wie folgt in Ihren Code einbinden:
require_once __DIR__ . " / MphpD / MphpD .php " ;
Erstellen Sie eine neue MphpD Instanz:
use FloFaber MphpD MphpD ;
use FloFaber MphpD MPDException ;
$ MphpD = new MphpD ([
" host " => " 127.0.0.1 " ,
" port " => 6600 ,
" timeout " => 5
]);
und mit MPD verbinden
try {
$ MphpD -> connect ();
} catch ( MPDException $ e ){
echo $ e -> getMessage ();
return false ;
}
Hier sind einige Beispiele dafür, was Sie damit machen können:
// 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 ();
Weitere Informationen finden Sie in der Dokumentation.
sockets
, die in den meisten PHP-Installationen standardmäßig enthalten sind. Eine Liste der PHP-Funktionen, MphpD für die Socket-Kommunikation benötigt:
fgets
fputs
fread
stream_get_meta_data
stream_set_chunk_size
stream_set_timeout
stream_socket_client