denmmtr / phomxplayer
phOMXPlayer - OMXPlayer包装shell脚本
dev-main
2021-08-28 20:18 UTC
Requires
- php: >=7.3
- ext-posix: *
Requires (Dev)
- phpunit/phpunit: ^9
This package is auto-updated.
Last update: 2024-09-29 02:58:59 UTC
README
OMXPlayer包装shell脚本,适用于REST/XML-RPC API或CLI实现。
安装
克隆
$ git clone https://github.com/dennmtr/phomxplayer.git
使用Composer
推荐的安装phOMXPlayer的方式是通过Composer
$ composer require dennmtr/phomxplayer:dev-main
Laravel框架
使用artisan命令optional发布配置
$ php artisan vendor:publish --tag phOMXPlayer
准备Raspberry Pi OS
将用户添加到video group(必需)
# usermod -a -G video <username>
将用户添加到audio group
# usermod -a -G audio <username>
为GPU保留至少128MB的系统内存(必需)
# echo "gpu_mem=128" >> /boot/config.txt
注意:需要重启...
使用方法
初始化
$player = new OMXPlayer([ 'adev' => 'hdmi', 'blank' => true ]); $player->play('sample.mp4');
请求
echo 'Movie duration: ' . $player->getDuration(); //same as... $command = new Commands\Duration(); echo 'Movie duration: ' . $command->getFormattedOutput();
查看预定义命令列表
验证
$input = 0.5; if (Commands\Volume::validateInput($input)) { $command = new Commands\Volume($input); echo 'New volume level: ' . $command->getFormattedOutput(); }
适当配置
$arguments = [ 'adev' => 'hdmi', 'blank' => true, 'no-keys' => true ]; $player = new OMXPlayer($arguments); $player->adev; // Returns the Arguments\Adev instance via magic method if exists or null. $player->adev->getShellArg(); // Returns '--adev hdmi' string, later passed in omxplayer execution. $player->adev->getValue(); // Returns 'hdmi' string. $player->adev = 'local'; // Sets a new adev argument instance with its variant value via magic method. $player->adev->getValue(); // Returns 'local' string. $player->map([ 'adev' => 'both', 'with-info' => false ]); $player->adev->getValue(); // Returns 'both' string. $player->with_info->getValue(); // Returns false bool. $player->blank->getValue(); // Returns true bool. $player->map([ 'adev' => new Arguments\Adev(Arguments\Adev::HDMI), 'blank' => new Arguments\Blank(false), 'with-info' => true, ]); $player->adev->getValue(); // Returns 'hdmi' string. $player->getShellArgs(false, false); // Returns '--adev hdmi --no-keys --with-info' string. $input = true; if (Arguments\Adev::isValid($input)) { $player->adev = $input; // It will never reach here because boolean true is not a valid Adev value. } $player->adev = $input; // It will throw an ArgumentException because boolean true is not a valid Adev value.
查看参数列表
直接调用
$dbus_client = new DBusClient(); $player = new OMXPlayer([], $dbus_client); // Optional if (!empty($player->pid)) { $stdout = $dbus_client->call( 'org.freedesktop.DBus.Properties.Get', [ ['string', 'org.mpris.MediaPlayer2.Player'], ['string', 'CanControl'], ]); // Assumes an active DBus session. Returns the raw stdout buffer as string }
预定义命令
一组可用的预定义命令...
参数列表
一组OMXPlayer shell参数...
开发
单元测试
不要忘记在phpunit.xml配置文件中为测试过程定义有效的绝对文件路径或有效的URL地址
<const name="TEST_URI" value="/file/path/sample.mp4"/>