Ejemplo n.º 1
0
 public function waitForMpd()
 {
     $this->jobPhase = 1;
     $recursionInterval = 3;
     // seconds
     $mpd = new \Slimpd\modules\mpd\mpd();
     $status = $mpd->cmd('status');
     if (isset($status['updating_db'])) {
         if ($this->waitingLoop === 0) {
             $this->waitingLoop = time();
             // fake total items with total seconds
             $this->itemCountTotal = (int) $this->maxWaitingTime;
             $this->beginJob(array(), __FUNCTION__);
         }
         if (time() - $this->waitingLoop > $this->maxWaitingTime) {
             cliLog('max waiting time (' . $this->maxWaitingTime . ' sec) for mpd reached. exiting now...', 1, 'red', TRUE);
             $this->finishJob(NULL, __FUNCTION__);
             \Slim\Slim::getInstance()->stop();
         }
         $this->itemCountProcessed = time() - $this->waitingLoop;
         $this->itemCountChecked = time() - $this->waitingLoop;
         $this->updateJob(array(), __FUNCTION__);
         //cliLog('waiting '. (time()-$this->waitingLoop - $this->maxWaitingTime)*-1 .' sec. until mpd\'s internal database-update has finished');
         sleep($recursionInterval);
         // recursion
         return $this->waitForMpd();
     }
     if ($this->waitingLoop > 0) {
         $this->itemCountProcessed = $this->itemCountTotal;
         cliLog('mpd seems to be ready. continuing...', 1, 'green');
         $this->finishJob(NULL, __FUNCTION__);
     }
     return;
 }
Ejemplo n.º 2
0
        $config['nowplaying_album'] = NULL;
    }
    $config['currentplaylist'] = $mpd->getCurrentPlaylist();
    // get all relational items we need for rendering
    $config['renderitems'] = array('genres' => \Slimpd\Genre::getInstancesForRendering($config['nowplaying_album'], $config['currentplaylist']), 'labels' => \Slimpd\Label::getInstancesForRendering($config['nowplaying_album'], $config['currentplaylist']), 'artists' => \Slimpd\Artist::getInstancesForRendering($config['nowplaying_album'], $config['currentplaylist']), 'albums' => \Slimpd\Album::getInstancesForRendering($config['nowplaying_album'], $config['currentplaylist']));
    $app->render('surrounding.twig', $config);
});
$app->get('/favorites(/)', function () use($app, $config) {
    $config['action'] = 'favorites';
    $app->render('surrounding.twig', $config);
});
$app->get('/mpdstatus(/)', function () use($app, $config) {
    $mpd = new \Slimpd\modules\mpd\mpd();
    # TODO: mpd-version check, v 0.20 has 'duration' included in status()
    # @see: http://www.musicpd.org/doc/protocol/command_reference.html#status_commands
    $config['mpd']['status'] = $mpd->cmd('status');
    $config['mpd']['status']['duration'] = $mpd->cmd('currentsong')['Time'];
    $percent = $config['mpd']['status']['elapsed'] / ($config['mpd']['status']['duration'] / 100);
    $config['mpd']['status']['percent'] = $percent >= 0 && $percent <= 100 ? $percent : 0;
    echo json_encode($config['mpd']['status']);
    $app->stop();
});
foreach (['mpdplayer', 'localplayer', 'widget-trackcontrol'] as $markupSnippet) {
    $app->get('/markup/' . $markupSnippet, function () use($app, $config, $markupSnippet) {
        // maybe we cant find item in mpd or mysql database because it has ben accessed via filebrowser
        $itemRelativePath = '';
        if ($markupSnippet === 'mpdplayer') {
            $mpd = new \Slimpd\modules\mpd\mpd();
            $config['item'] = $mpd->getCurrentlyPlayedTrack();
        } else {
            if (is_numeric($app->request->get('item')) === TRUE) {