41 lines
932 B
PHP
41 lines
932 B
PHP
<?php
|
|
|
|
namespace NoccyLabs\PulseAudio\Helper;
|
|
|
|
class Pacmd
|
|
{
|
|
public static function call($command, array $args=[])
|
|
{
|
|
// assemble command lin
|
|
$cmdl = array_merge([ $command ], $args);
|
|
$cmdl = join(" ", array_map("escapeshellarg", $cmdl));
|
|
|
|
echo "$ pacmd {$cmdl}\n";
|
|
|
|
// call pacmd
|
|
exec("pacmd {$cmdl}", $output, $retval);
|
|
|
|
// handle errors
|
|
if ($retval != 0) {
|
|
throw new \RuntimeException("Failed to call pacmd. exitcode={$retval}");
|
|
}
|
|
|
|
// return output
|
|
return $output;
|
|
}
|
|
|
|
public static function query($command, array $args=[])
|
|
{
|
|
$output = Pacmd::call($command, $args);
|
|
|
|
$status = array_shift($output);
|
|
// printf("[pacmd] %s\n", $status);
|
|
|
|
$parser = new PacmdListParser();
|
|
$output = $parser->parse($output);
|
|
|
|
return $output;
|
|
}
|
|
}
|
|
|