PHP code example of flofaber / mphpd

1. Go to this page and download the library: Download flofaber/mphpd library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

flofaber / mphpd example snippets






use FloFaber\MphpD\MphpD;
use FloFaber\MphpD\MPDException;

$mphpd = new MphpD([
  "host" => "127.0.0.1",
  "port" => 6600,
  "timeout" => 5
]);

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();