QT前台+MPlayer后台视频播放器

上一篇 / 下一篇  2012-03-31 10:10:36 / 个人分类:QT开发

   对于QT视频播放器,网上有很多,准备工作和基础知识,在下面的两个网址里面有详细的介绍

http://mobile.51cto.com/symbian-268181.htm

http://mobile.51cto.com/symbian-269696.htm

http://www.mplayerhq.hu/DOCS/tech/slave.txt slave.txt文档

http://doc-snapshot.qt-project.org/4.8/qprocess.html#ProcessState-enum QProcess文档

先要实现的是视频播放器的循环播放:单曲循环和播放列表视频的循环

1、单曲视频播放的循环:

   在MPlayer源码的slave.txt文档里面有一个loop参数 具体的形式如下:

loop <value> [abs]
    Adjust/set how many times the movie should be looped. -1 means no loop,
    and 0 forever.

# process -> write("loop 1\n");在程序中添加这段代码就可以实现单曲循环

2、播放列表的视频循环:

假设:程序已经实现了视频的上一首和下一首播放功能

在这里讲解一下:

(1)QProcess的状态:

enum QProcess::ProcessState

This enum describes the different states of QProcess.

ConstantValueDescription
QProcess::NotRunning0The process is not running.
QProcess::Starting1The process is starting, but the program has not yet been invoked.
QProcess::Running2The process is running and is ready for reading and writing.

当视频播放完毕后,QProcess的状态处于NotRunning状态,然后我们通过QProcess::statChange()信号量发出的信号判断当前的进程状态,如果是NotRunning,则使用Qtimer等待3秒钟(如果不加延迟会报套接字错误)调用播放下一首歌曲的按钮的click()功能,实现了播放列表的循环播放。

播放功能函数player():

void MainWindow::player()

{

  mplayerProcess->close();

   currentFileName="/home/chuzhou.ogg";

   QStringList args;

   args << tr("-slave");

   args << "-quiet";

   args << "-vo" << "null";

   args << currentFileName;

connect(mplayerProcess, SIGNAL(stateChanged(QProcess::ProcessState)), this, SLOT(get_currentstat()));

   mplayerProcess->start(mplayerProgram, args);

 

void MainWindow::get_currentstat()

{

   if(mplayerProcess->state()==0){

        qDebug() << "0";

//延迟3秒中,点击下一首按钮

         QTimer::singleShot(3000, this, SLOT(on_pushButton_6_clicked()));   }

   if(mplayerProcess->state()==1){

        qDebug() << "1";

   }

   if(mplayerProcess->state()==2){

        qDebug() << "2";

   }

}

void MainWindow::show_state()

{

   qDebug() <<"show_state";

   disconnect(mplayerProcess, SIGNAL(stateChanged(QProcess::ProcessState)), this, SLOT(get_currentstat()));

    player();

}

//点击下一首音乐按钮

void MainWindow::on_pushButton_6_clicked()

{

   qDebug() << "on_pushButton_6_clicked()";

   show_state();

}


TAG: MPlayer mplayer QT QT视频播放器

 

评分:0

我来说两句

Open Toolbar