天天看点

QT调用mplayer 暂停 进度

安装mplayer,之后目录下会有个mplayer-core.exe 提取出来。放到源码下面。

代码:

QProcess *mplayerProcess = new QProcess(this);

QString exefile = "mplayer-core.exe";

QStringList arg;

// arg << "-slave";

// arg << "-quiet";

// arg << "-idle";        如果想不播放歌曲的时候就退出mplayer,那么这个参数不要加

arg << "D:/temp/PhonoTest/PhonoTest/1.mp3";

mplayerProcess->start(exefile,arg);

这个文件有12.9M。完全提取?? 暂时不明确。

参数怎么加? 暂时不明确、

通过定义一个QProcess对象调用已编译好的Mplayer。

  QProcess *process = new QProcess();

  process->setProcessChannelMode(QProcess::MergedChannels);

  Process->start(“mplayer –ac –mad xxxxx”);

  在命令中添加 -slave 和 -quiet就可以通过命令设置Mplayer实现相应的功能。在mplayer源码中的,slave.txt中对这些命令有详细的

  Process->start(“mplayer –slave –quiet –ac –mad xxxxx”);

  1.暂停功能

  通过如下代码可以设置Mplayer暂停。

  process->write(“pause/n”);

  执行这段代码的时候如果是播放状态就会暂停,暂停状态时就会继续播放。

  2.获取播放文件的总时间和当前播放进度。

  执行下面代码时,Mplayer将时间在标准输出显示。

  process->write("get_time_pos/n");

  process->write("get_time_length/n");

  通过如下代码即可读出我们需要的信息:

  connect(process,SIGNAL(readyReadStandardOutput()),this,SLOT(back_message_slots()));

  process有可读取的信息时,发出信号,在槽函数back_message_slots()中读取信息。

  void MPlayer::back_message_slots()

  {

  while(process->canReadLine())

  {

  QString message(process->readLine());

  //message即为读取的信息我们可以根据需要取我们要的信息如

  //文件总时间为:ANS_LENGTH=23.00

  //当前时间为:ANS_TIME_POSITION=23.00

  }

  }

  3.快进功能

  seek <value> [type]

  Seek to some place in the movie

  0 is a relative seek of +/- <value> seconds (default).

  1 is a seek to <value> % in the movie.

  2 is a seek to an absolute position of <value> seconds.

  下面代码即可实现快进功能:

  process->write(“seek ** 1/n”);

  4.音量调节

  volume <value> [abs]

  Increase/decrease volume or set it to <value> if [abs] is nonzero.

  下面代码即可实现快进功能:

  Process->write(“volume -1/n”); //音量减小

  Process->write(“volume +1/n”); //音量增加

  5.静音功能

  mute [value]

  Toggle sound output muting or set it to [value] when [value] >= 0

  (1 == on, 0 == off).

  下面代码即可实现快进功能:

  process->write("mute 0/n"); //开启静音

  process->write("mute 1/n"); //关闭静音

  6.定位视频窗口

  通过上面的代码基本功能实现了,可是播放视频的时候发现又弹出一个窗口。并没有出现在我们的窗口里。

  如下代码即可时间窗口的定位。

  QString common = "mplayer -slave -quiet -ac mad -zoom movie/" + file_name + " -wid " + QString::number(widget->winId());

  process->start(common);

  红色部分实现串口的定位。Widget是一个QWidget对象。通过winId可以获得一个数字,-wid既将视频输出定位到widget窗体部件中。

  注意:-wid参数只在X11、directX和OpenGL中适用。