Example #1
0
 private static function process()
 {
     if (PlaylistService::checkScreen()) {
         $playlist = PlaylistService::getPlaylist();
         if (!($screen = PlaylistService::getScreen())) {
             System_Daemon::notice('playlist %s ended', $playlist['name']);
             self::killScreen(PlaylistService::getPrevScreenOwnId());
             PlaylistService::disablePlaylist($playlist['id']);
             PlaylistService::savePlaylist();
             return true;
         }
         System_Daemon::notice('screen has been changed to %s/%d (%d assets)', $playlist['name'], PlaylistService::getScreenId(), count($screen['assets']));
         // TODO: foreach instead of [0]
         switch ($screen['assets'][0]['type']) {
             case 'clock':
                 $pid = intval(shell_exec('xclock > /dev/null 2>&1 & echo $!'));
                 break;
             case 'video':
                 if (strpos($screen['assets'][0]['filename'], '/') === false) {
                     $filename = sprintf('%s./data/assets/video/%s', __DIR__ . '/../../', $screen['assets'][0]['filename']);
                 } else {
                     $filename = $screen['assets'][0]['filename'];
                 }
                 if (file_exists('/usr/bin/omxplayer')) {
                     $command = 'timeout %s omxplayer %s > /dev/null 2>&1 & echo $!';
                     $type = 'kill';
                 } elseif (file_exists('/usr/bin/mplayer')) {
                     $command = 'timeout %s mplayer -fs %s > /dev/null 2>&1 & echo $!';
                     $type = 'kill';
                 } else {
                     continue;
                 }
                 $command = sprintf($command, round($screen['duration'] / 1000) + 3, escapeshellarg($filename));
                 System_Daemon::notice($command);
                 $pid = intval(shell_exec($command));
                 break;
             case 'image':
                 if (strpos($screen['assets'][0]['filename'], '/') === false) {
                     $filename = sprintf('%s./data/assets/image/%s', __DIR__ . '/../../', $screen['assets'][0]['filename']);
                 } else {
                     $filename = $screen['assets'][0]['filename'];
                 }
                 $command = sprintf('timeout %s feh --auto-zoom --borderless --fullscreen %s > /dev/null 2>&1 & echo $!', round($screen['duration'] / 1000) + 2, escapeshellarg($filename));
                 System_Daemon::debug($command);
                 $pid = intval(shell_exec($command));
                 $type = 'kill';
                 break;
             default:
                 System_Daemon::warning('{appName} received unrecognized task: %s', $s);
                 break;
         }
         if (isset($pid)) {
             self::$pids[PlaylistService::getScreenOwnId()] = array('type' => $type, 'pid' => $pid);
             System_Daemon::info('new process with PID %s has been started', $pid);
         }
     }
     return true;
 }
Example #2
0
File: app.php Project: rlanyi/kiosk
    PlaylistService::init();
    $pldata = array();
    foreach (PlaylistService::getData() as $pld) {
        $pldata[$pld['id']] = $pld['name'];
    }
    $form = $app['form.factory']->createBuilder('form')->add('playlist', 'choice', array('choices' => $pldata, 'expanded' => true, 'constraints' => $request->request->get('stop') ? array() : array(new Assert\Choice(array_keys($pldata)), new Assert\NotNull())))->add('security', 'password', array('constraints' => array(new Security()), 'attr' => array('placeholder' => 'Biztonsági kód'), 'label' => 'Biztonsági kód'))->getForm();
    if ('POST' == $request->getMethod()) {
        $form->bind($request);
        if ($form->isValid()) {
            $data = $form->getData();
            $saved = false;
            if ($request->request->get('stop')) {
                PlaylistService::disablePlaylist(true);
                $saved = PlaylistService::savePlaylist();
            }
            if ($request->request->get('play')) {
                PlaylistService::disablePlaylist(true);
                PlaylistService::enablePlaylist($data['playlist']);
                $saved = PlaylistService::savePlaylist();
            }
            if ($saved) {
                $daemon = new Kiosk\Daemon();
                $daemon->reload();
            }
            //      return $app->redirect('/playlist');
        }
    }
    // display the form
    return $app['twig']->render('playlist.twig', array('form' => $form->createView(), 'permission_error' => !PlaylistService::isWritable()));
});
return $app;