예제 #1
0
파일: idle.php 프로젝트: jahudka/react-mpd
<?php

require __DIR__ . '/../vendor/autoload.php';
$config = ['connection' => ['host' => '127.0.0.1', 'port' => 6600, 'socket' => '/run/mpd/socket'], 'options' => ['password' => null]];
$loop = React\EventLoop\Factory::create();
$connection = new Jahudka\MPD\Connection\React($loop, $config['connection']);
$client = new Jahudka\MPD\Client($connection, $config['options']);
$loop->nextTick(function () use($client) {
    $client->on('update', function ($subsystem) {
        echo "Update: {$subsystem}\n";
    });
    $client->idle(Jahudka\MPD\Client::SUBSYSTEM_PLAYER);
});
// even if the client is in idle mode & listening for server events,
// you can still use the API - the client will transparently exit
// idle mode, issue your commands and then resume being idle
$loop->addTimer(10, function () use($client) {
    echo "Playing song\n";
    $client->batch()->clear()->add('Path/To/Song.mp3')->play()->run();
});
$loop->run();
예제 #2
0
<?php

require __DIR__ . '/../vendor/autoload.php';
$config = ['connection' => ['host' => '127.0.0.1', 'port' => 6600, 'socket' => null], 'options' => ['password' => null]];
$connection = new Jahudka\MPD\Connection\Native($config['connection']);
$client = new Jahudka\MPD\Client($connection, $config['options']);
$client->clear()->then(function () use($client) {
    return $client->add('Path/To/Song.mp3');
})->then($client->command('toggleRepeat', false))->then($client->command('toggleRandom', false))->then($client->play)->then($client->getStatus)->then(function ($status) {
    foreach ($status as $k => $v) {
        echo $k . ': ' . $v . "\n";
    }
    exit(0);
}, function ($err) {
    if ($err instanceof \Exception) {
        echo $err->getMessage() . "\n";
    } else {
        echo "Unknown error\n";
    }
    exit(-1);
});
while (true) {
    usleep(100000);
    // sleep 100 ms
    $connection->receive();
    // and see if there's any new data
}
예제 #3
0
파일: batch.php 프로젝트: jahudka/react-mpd
<?php

require __DIR__ . '/../vendor/autoload.php';
$config = ['connection' => ['host' => '127.0.0.1', 'port' => 6600, 'socket' => null], 'options' => ['password' => null]];
$loop = React\EventLoop\Factory::create();
$connection = new Jahudka\MPD\Connection\React($loop, $config['connection']);
$client = new Jahudka\MPD\Client($connection, $config['options']);
$loop->nextTick(function (React\EventLoop\LoopInterface $loop) use($client) {
    $client->batch()->clear()->add('Path/To/Song.mp3')->toggleRepeat(false)->toggleRandom(false)->play()->getStatus()->run()->then(function ($status) use($loop) {
        foreach ($status as $k => $v) {
            echo $k . ': ' . $v . "\n";
        }
        $loop->stop();
    }, function ($err) use($loop) {
        if ($err instanceof \Exception) {
            echo $err->getMessage() . "\n";
        } else {
            echo "Unknown error\n";
        }
        $loop->stop();
    });
});
$loop->run();