是否有使用 PId 停止和暂停 mplayer 的命令?

发布于 2024-10-19 14:57:54 字数 323 浏览 2 评论 0原文

我正在使用播放按钮从 qt 应用程序播放 mplayer。我有两个按钮,称为暂停和停止。对于播放按钮,我使用了 system ("mplayer "+s.toAscii()+"&"); 其中 s 是播放列表。

对于暂停按钮,我使用了 system("p"); 但它不起作用。我可以使用 system("ps -A |grep mplayer > PID.txt"); 将 mplayer 的进程 ID 存储到文本文件中。

是否有任何命令可以使用 PId 停止和暂停 mplayer?

I am playing mplayer from my qt application using the play button. I have two buttons called pause and stop. For play button I used system ("mplayer "+s.toAscii()+"&"); where s is the playlist.

For the pause button I used system("p"); but it is not working. I am able to store the process id of mplayer to a text file using system("ps -A |grep mplayer > PID.txt");.

Is there any command to stop and pause the mplayer using the PId?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

飘逸的'云 2024-10-26 14:57:55

您可能想要的是 MPlayer 的从属模式输入,这样可以轻松地从另一个程序向其发出命令。您可以在启动 MPlayer 时为其指定 -slave 命令行选项,以此模式启动 MPlayer。

在此模式下,MPlayer 会忽略其标准输入绑定,而是接受不同的文本命令词汇表,这些命令可以一次发送一个,并以换行符分隔。如需支持的命令的完整列表,请运行 mplayer -input cmdlist

由于您已将问题标记为 Qt,因此我假设您正在使用 C++。下面是一个 C 语言示例程序,演示如何使用 MPlayer 的从属模式:

#include <stdio.h>
#include <unistd.h>

int main()
{
    FILE* pipe;
    int i;

    /* Open mplayer as a child process, granting us write access to its input */
    pipe = popen("mplayer -slave 'your_audio_file_here.mp3'", "w");

    /* Play around a little */
    for (i = 0; i < 6; i++)
    {
        sleep(1);
        fputs("pause\n", pipe);
        fflush(pipe);
    }

    /* Let mplayer finish, then close the pipe */
    pclose(pipe);
    return 0;
}

What you probably want is MPlayer's slave mode of input, which makes it easy to give it commands from another program. You can launch MPlayer in this mode by giving it the -slave command line option when launching it.

In this mode, MPlayer ignores its standard input bindings and instead accepts a different vocabulary of text commands that can be sent one at a time separated by newlines. For a full list of commands supported, run mplayer -input cmdlist.

Since you have tagged the question as Qt, I'm going to assume you are using C++. Here's an example program in C demonstrating how to use MPlayer's slave mode:

#include <stdio.h>
#include <unistd.h>

int main()
{
    FILE* pipe;
    int i;

    /* Open mplayer as a child process, granting us write access to its input */
    pipe = popen("mplayer -slave 'your_audio_file_here.mp3'", "w");

    /* Play around a little */
    for (i = 0; i < 6; i++)
    {
        sleep(1);
        fputs("pause\n", pipe);
        fflush(pipe);
    }

    /* Let mplayer finish, then close the pipe */
    pclose(pipe);
    return 0;
}
铃予 2024-10-26 14:57:55

据我所知,没有PID。不过,请检查从属模式(-slave)。来自 man mplayer:

打开从模式,其中 MPlayer 作为其他程序的后端。 MPlayer 不会拦截键盘事件,而是从 stdin 读取由换行符 (\n) 分隔的命令。

这样你就可以完美地控制它。

Not with a PID as far as I know. Check out slave mode (-slave) though. From man mplayer:

Switches on slave mode, in which MPlayer works as a backend for other programs. Instead of intercepting keyboard events, MPlayer will read commands separated by a newline (\n) from stdin.

You can control it perfectly that way.

删除→记忆 2024-10-26 14:57:55

是的,在从属模式下使用 mplayer。这样你就可以从你的程序向它传递命令。看看 qmpwidget。它是开源的,应该可以解决您所有的麻烦。有关命令,请检查 mplayer 站点或搜索 mplayer 从属模式命令。

Yes use mplayer in the slave mode. That way you can pass commands to it from your program. Take a look at qmpwidget. Its open source and should solve all of your troubles. For commands check the mplayer site or search for mplayer slave mode commands.

蛮可爱 2024-10-26 14:57:55

我在 QT 中使用 mplayer 编写了一个类似的程序。我使用QProcess来控制mplayer。

这是代码的某些部分。在函数 playstop() 中,您只需发送“q”,它就会存在 mplayer。如果您发送“p”,它将暂停 mplayer。我希望它对您有用。

主要.h

#ifndef MAIN_H
#define MAIN_H
#include "process.h"
class Main : public QMainWindow
{
public:  
   Process  m_pProcess1; 
Q_OBJECT
public:
  Main():QMainWindow(),m_pProcess1()
{
};

 ~Main()
      {};


public slots:

void play()

{
m_pProcess1.setProcessChannelMode(QProcess::MergedChannels); 
        m_pProcess1.start("mplayer -geometry 0:0 -vf scale=256:204 -noborder -af scaletempo /root/Desktop/spiderman.flv");

};

void playstop()

{
m_pProcess1.setProcessChannelMode(QProcess::MergedChannels); 
        m_pProcess1.writeData("q",1);


};

};

#endif

I've written a similar program in QT which uses mplayer. I used QProcess to control mplayer.

Here is the some part of code. In the function playstop() you just send "q" and it exists the mplayer. If you send "p" it will pause mplayer.I hope it will be usefull for you.

Main.h

#ifndef MAIN_H
#define MAIN_H
#include "process.h"
class Main : public QMainWindow
{
public:  
   Process  m_pProcess1; 
Q_OBJECT
public:
  Main():QMainWindow(),m_pProcess1()
{
};

 ~Main()
      {};


public slots:

void play()

{
m_pProcess1.setProcessChannelMode(QProcess::MergedChannels); 
        m_pProcess1.start("mplayer -geometry 0:0 -vf scale=256:204 -noborder -af scaletempo /root/Desktop/spiderman.flv");

};

void playstop()

{
m_pProcess1.setProcessChannelMode(QProcess::MergedChannels); 
        m_pProcess1.writeData("q",1);


};

};

#endif
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文