bash Linux Shell:VLC 编程
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8943464/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Linux Shell: VLC programming
提问by Willem Van Onsem
Is there a way to manipulate VLC with a Linux shell script without the script waiting for VLC to close.
有没有办法用 Linux shell 脚本操作 VLC,而无需等待 VLC 关闭的脚本。
cvlc test.mp3
echo "Now playing!"
sleep 200
cvlc://pause:60
This code keeps running VLC until the file is completed, and then evidently it is to late to pause the file.
这段代码一直运行 VLC 直到文件完成,然后显然暂停文件为时已晚。
回答by Abhijeet Rastogi
You need to use dbus interface of VLC.
您需要使用 VLC 的 dbus 接口。


Now, you can use the mprisinterface of VLC. It's a standard for most players like clementine, banshee, songbird, spotify etc.
现在,您可以使用VLC的mpris接口。这是大多数播放器的标准,例如 clementine、banshee、songbird、spotify 等。
So, lets suppose you want to Pause the currently playing song.
因此,假设您想暂停当前播放的歌曲。
dbus-send --print-reply --session --dest=org.mpris.vlc /Player org.freedesktop.MediaPlayer.Pause
To play a song:
播放歌曲:
dbus-send --print-reply --session --dest=org.mpris.vlc /Player org.freedesktop.MediaPlayer.Play
I generally use qdbusviewer to know about the dbus-interface available to me.
我通常使用 qdbusviewer 来了解我可用的 dbus 接口。
回答by Jeff M
It looks like you can redirect from standard input or a named pipe. For more complicated things you could use libvlc.
看起来您可以从标准输入或命名管道重定向。对于更复杂的事情,您可以使用 libvlc。
回答by Dwight Spencer
Dbus is one way but dbus does not exist on all systems. The more common method would be to use the rc interface:
Dbus 是一种方式,但并非所有系统上都存在 dbus。更常见的方法是使用 rc 接口:
cvlc -I rc --rc-host localhost:11337 -d
cvlc -I rc --rc-host localhost:11337 -d
Then one can use netcat to pipe commands into the tcp socket. For example:
然后可以使用 netcat 将命令通过管道传输到 tcp 套接字中。例如:
vlc -I rc --rc-host localhost:11337 test.mp3 -d &
echo "Now playing!"
sleep 200
echo pause | netcat localhost 11337
EDIT:
编辑:
After testing with a few other interfaces I have discovered the oldrcinterface accepts UNIX domain sockets thus the following will work as well with out needing to play around with firewalls or worry about anyone else on the network messing around with your vlc instance.
在使用其他一些接口进行测试后,我发现该oldrc接口接受 UNIX 域套接字,因此以下内容也可以正常工作,而无需使用防火墙或担心网络上的其他人会与您的 vlc 实例混淆。
vlc -I oldrc --rc-unix /var/run/vlc.sock -d
echo "Now Playing!"
sleep 200
echo "pause" | netcat -U /var/run/vlc.sock

