node.js - Node 使用 child_process 启动 VLC Player

标签 node.js vlc child-process

我有一个 POST 函数,我尝试使用 child_process 启动 VLC 播放器。我正在使用最新的 Raspbian 版本。

router.post('/', function (req, res) {
    let spawn = require('child_process').spawn;
    let vlc = spawn('vlc');
    vlc.stderr.on('data', function(data) {
        console.log(data.toString());
    });
    vlc.on('exit', function(code){
        console.log('Exit code: ' + code);
    });
    res.send({success: true})
});

触发请求后,我收到此消息:

VLC is not supposed to be run as root. Sorry. If you need to use real-time priorities and/or privileged TCP ports you can use vlc-wrapper (make sure it is Set-UID root and cannot be run by non-trusted users first).

由于 VLC 无法以 root 身份运行,因此我将 UID 参数添加到 vlc 启动脚本中,现在看起来像这样:

let vlc = spawn('vlc' ,{uid: 1000});

其中UID:1000是我一直使用的用户的ID。

触发请求后,我在日志中收到另一条消息:

[016f9960] main libvlc error: cannot open config file (/root/.config/vlc/vlcrc): Permission denied

Home directory not accessible: Permission denied

[01762eb0] vlcpulse audio output error: PulseAudio server connection failure: Connection refused

[0176bde8] dbus interface error: Failed to connect to the D-Bus session daemon: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11

[0176bde8] main interface error: no suitable interface module [016f9960] main libvlc error: interface "dbus,none" initialization failed

[0176c7a8] main interface error: no suitable interface module [016f9960] main libvlc error: interface "globalhotkeys,none" initialization failed

[016f9960] main libvlc: Running vlc with the default interface. Use 'cvlc' to use vlc without interface.

error: XDG_RUNTIME_DIR not set in the environment.

[0176c7a8] skins2 interface error: cannot initialize OSFactory

[017614e0] main playlist: playlist is empty

[0176c7a8] [cli] lua interface: Listening on host "*console".

玩家没有运行。但如果我通过 ssh 运行相同的命令,它就会运行。什么可能导致 Node 无法运行?

最佳答案

问题是我的服务器正在使用

运行

nodemon

我确实尝试了一切,然后当我准备放弃时,我不小心使用 node 命令以正常方式启动了服务器。 VLC 正在启动,没有任何错误。我不必在参数中传递任何用户 ID。它工作得很好,就像这样:

let spawn = require('child_process').spawn;
let vlc = spawn('vlc');

我真的很好奇为什么 nodemon 会导致这种行为。

关于node.js - Node 使用 child_process 启动 VLC Player,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54058502/

相关文章:

node.js - 如何配置 WebStorm 指向 VM Node 解释器

node.js - 如何从 MEAN Stack 中的 Express get API 中的函数传递信息

ubuntu - Gstreamer "filesrc"插件缺少与 Fedora/Centos/Ubuntu 中的 VLC 交互?在它可用之前

ubuntu-12.04 - 在 Ubuntu 12.04 上使用 VLC 进行流式传输返回套接字绑定(bind)错误(权限被拒绝)

node.js - 缺少来自 Node 中子进程的信息

c# - 在需要执行 C# 应用程序的 Ubuntu 上运行的 Node 服务器 - 如何?

javascript - 为什么我的 AJAX 每两分钟调用一次?

python - 如何在 Python 中安装 VLC 模块

node.js - 检查是否全局安装了特定的 NPM 包

javascript - Node.js - 按值查找数组中的对象