如何使用Python子进程添加到VLC播放列表队列

2024-07-03 08:10:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试使用python2.7subprocess库以编程方式将歌曲添加到VLC播放器队列中。在

here和{a2},我可以启动VLC播放器并播放一首歌(或从一开始就对歌曲进行排队)

from subprocess import Popen
vlcpath = r'C:\Program Files (x86)\VideoLAN\VLC\vlc.exe'
musicpath1 = r'path\to\song1.mp3'
musicpath2 = r'path\to\song2.mp3'
p = Popen([vlcpath,musicpath1]) # launch VLC and play song
p = Popen([vlcpath,musicpath1,musicpath2]) # launch VLC and play/queue songs

问题是我不知道启动时的整个队列播放列表。我希望能够将歌曲添加到已经运行的VLC进程的队列中。请问我该怎么做?在

here开始,我认为合适的命令行条目是:

^{pr2}$

但我不知道在subprocess中执行此操作的语法。我试了几件事,但都没用:

  • 再次调用Popen(打开一个新进程)
  • 调用p.communicate(我以为这是如何输入stdin命令的)

Tags: andtopathhere队列launch播放器歌曲
1条回答
网友
1楼 · 发布于 2024-07-03 08:10:58

要在Windows上运行命令:vlc.exe started-from-file playlist-enqueue "2.wmv" 使用subprocess模块:

from subprocess import Popen

cmd = 'vlc.exe  started-from-file  playlist-enqueue "2.wmv"'
p = Popen(cmd) # start and forget
assert not p.poll() # assert that it is started successfully

要等待命令完成:

^{pr2}$

But how do I run that command a second time on the same p process? Your code starts a new instance of VLC, rather than running that on top of the p that was already open. I found that if I run the vlc.exe started-from-file playlist-enqueue "2.wmv" command multiple times manually (in a command prompt window), it correctly launches vlc (the first time) and then adds to queue (on subsequent calls). So I think I just need to be able to run the code you suggested multiple times "on top of itself"

每个Popen()都会启动一个新的进程。每次在命令行中手动运行该命令时,它都会启动一个新进程。它可能取决于系统上当前的vlc配置,无论它保留多个vlc实例,还是运行不同的命令(不同的命令行参数)。在

相关问题 更多 >