如何在 Linux 上运行带有来自 PHP Web 脚本的音频扬声器输出的 mplayer?
我使用用户名:stackoverflow 登录到 linux feora 15 发行版。 我的浏览器在本地系统中执行 PHP 脚本,以使用 PHP system("mplayer /tmp/stackoverflow.wav")、passthru("mplayer /tmp/stackoverflow.wav") 命令播放音乐。比如linux命令。
作为 stackoverflow 用户,我听不到任何音频。但我可以看到 mplayer /tmp/stackoverflow.wav 正在运行,其音频持续时间为 8 分钟。
我的问题是:我如何使用 PHP system("mplayer /tmp/stackoverflow.wav");切换用户并运行相同的命令,以便我可以用 PHP 听到音乐?
<?php
// for example
switchuser("su stackoverflow password");
system("mplayer /tmp/itworks.wav");
?>
I am logged in to linux feora 15 distro with username: stackoverflow.
My browser execute in the local system a PHP script to play a music using PHP system("mplayer /tmp/stackoverflow.wav"), passthru("mplayer /tmp/stackoverflow.wav") command. Such as linux command.
As a user stackoverflow i dont hear any audio. But i can see that mplayer /tmp/stackoverflow.wav is running which has duration of 8minutes audio.
My question is: how can i use PHP system("mplayer /tmp/stackoverflow.wav"); to switch user and run the same command, so that i can hear my music with my PHP?
<?php
// for example
switchuser("su stackoverflow password");
system("mplayer /tmp/itworks.wav");
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我也想做同样的事情。
当我尝试仅通过
shell_ecex();
运行 mplayer 时,它不会选择pulseaudio 进行输出。即使我将其包含到命令-aopulse
中,它也不起作用。当我尝试使用 sudo 运行 mplayer 命令时(我将 www-data 添加到 sudoers 文件中),mplayer 显然开始播放(根据资源使用情况),但没有输出。当我手动终止 mplayer 实例时,整个声音输出都会被阻止,即使我通过控制台启动 mplayer 也是如此。
您对如何通过 PHP 运行 mplayer 有什么建议吗?
编辑:我有一个解决方案!我的命令如下所示:
这也会停止 php 脚本等待 mplayer 的结果,因此它启动 mplayer 并继续操作。
I would like to do the same.
When I try to run mplayer just via
shell_ecex();
it does not select pulseaudio for output. Even when I include into the command-ao pulse
it doesn't work.When I try to run the mplayer command with sudo (I added www-data to the sudoers file), mplayer apparently starts playing (according to ressource usage) but there is no output. When I kill the mplayer instance manually the whole sound output is blocked, even when I launch mplayer via the console.
Do you have any tips for me how to run mplayer via PHP?
Edit: I have a solution! My command looks like this:
This also stops the php script from waiting for a result from mplayer, so it starts mplayer and continues operation.
您问题的直接答案是使用
sudo
,如“但是,我不确定这是否能解决您的问题”。首先,你想把声音输出到哪里?服务器还是客户端/浏览器?上述技术将在服务器上运行。对于浏览器,您需要让客户端将 .wav 文件作为对象或类似文件加载并处理它,大概是通过插件。
您提到您可以看到正在运行的 mplayer 进程?如果您在服务器上(或者服务器和客户端位于同一台物理计算机上)并且听不到任何输出,则可能存在其他问题。 Web 服务器进程用户可能没有使用声卡的权限,但我怀疑 mplayer 进程会持续这么长时间而不会因“权限被拒绝”错误而终止。为了弄清楚这一点,我想我们需要更多信息
The direct answer to your question would be to use
sudo
, as inBut, I'm not sure this will solve your problem. Firstly, where do you want the sound outputted? The server or the client/browser? The above technique will work on the server. For the browser, you'd need to get the client to load the .wav file as an object or some such and deal with it, presumably via a plugin.
You mention that you can see a running mplayer process though? If you are at the server (or the server and client are on the same physical machine) and you can't hear any output, then there's something else going on. It's possible that the web server process user doesn't have permission to use the audio card, but then I doubt the mplayer process would continue for so long without terminating with "permission denied" error. To figure this out, we'd need more info I guess