public static function replacePlaylist($args, $shuffle = false) { // connect to MPD static::connect(); // get the songs as defined by the arguments $songs = Music::getSongList($args); // get the ID of the song to play $song_id = array_pop($args); // clear the current playlist MPD::clear(); // a variable to save the ID of the song to play $mpd_id = null; // step through the songs foreach ($songs as $s) { // add each song to the playlist $values = MPD::send('addid', 'file://' . $s->filenamepath); // does this song correspond to the the song to play? if ($values['status'] == 'OK' && $s->id == $song_id) { $mpd_id = trim(substr($values['values'][0], 3)); } } // start playing the selected song if (!$shuffle && $mpd_id) { // turn off random play MPD::send('random', 0); // play the requested song MPD::send('playid', $mpd_id); } else { // turn on random play MPD::send('random', 1); // start playing MPD::send('play'); } }