php-pulseaudio/src/Helper/Pactl.php

29 lines
649 B
PHP

<?php
namespace NoccyLabs\PulseAudio\Helper;
class Pactl
{
public static function call($command, array $args=[])
{
// assemble command lin
$cmdl = array_merge([ $command ], $args);
$cmdl = join(" ", array_map("escapeshellarg", $cmdl));
echo "$ pactl {$cmdl}\n";
// call pacmd
exec("pactl {$cmdl}", $output, $retval);
// handle errors
if ($retval != 0) {
throw new \RuntimeException("Failed to call pacmd. exitcode={$retval}");
}
// return output
if (count($output)>0) {
return $output[0];
}
}
}