首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > QT开发 >

QT编写的视频播放器出有关问题

2012-04-06 
QT编写的视频播放器出问题使用qt编写了一个视频播放器,在播放mp4视频的时候有音频但是不出现画面,求解答!~

QT编写的视频播放器出问题
使用qt编写了一个视频播放器,在播放mp4视频的时候有音频但是不出现画面,求解答!~

C/C++ code
#include <QtGui>#include "implayer.h"#include "ui_implayer.h"#include <QFile>#include<QTextStream>#include<QIcon>IMplayer::IMplayer(QWidget *parent) :    QMainWindow(parent),    ui(new Ui::IMplayer){    isMute = 0;    isPlay = 1;    isLength = 1;    timePos = 0;    timeLength = 0;    ui->setupUi(this);    ui->scheduleSlider->setRange(0,999);    ui->voiceSlider->setRange(0, 99);    mplayerProcess = new QProcess(this);    mplayerProcess->setProcessChannelMode(QProcess::MergedChannels);    //mplayerProgram = tr("D:/workstation/IMplayer/mplayer/mplayer.exe");    mplayerProgram = tr("/usr/bin/mplayer");    timeClock = new QTimer(this);    connect(mplayerProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(back_Message_slot()));    connect(timeClock, SIGNAL(timeout()), this, SLOT(back_posMessage_slot()));}IMplayer::~IMplayer(){    delete ui;}void IMplayer::setUI(){}void IMplayer::play(QString fileName){    mplayerProcess->close();    ui->posTimeLineEdit->setText("00:00:00");    ui->lengthTimeLineEdit->setText("00:00:00");    ui->scheduleSlider->setValue(0);    ui->voiceSlider->setValue(99);    ui->playPushButton->setEnabled(1);    ui->pausePushButton->setEnabled(1);    ui->stopPushButton->setEnabled(1);    ui->stepPushButton->setEnabled(1);    ui->backPushButton->setEnabled(1);    ui->scheduleSlider->setEnabled(1);    ui->voiceSlider->setEnabled(1);    ui->quietPushButton->setEnabled(1);    QStringList args;    args << tr("-slave");    args << "-quiet";    args << "-zoom";    args << tr("-wid") << QString::number((unsigned int)(ui->widget->winId()));    args << "-vo" << "directx:noaccel";    args << fileName;    timePos = 0;    //ui->posTimeLineEdit->setText("00:00:00");    timeLength = 1;    isLength = 1;    mplayerProcess->start(mplayerProgram, args);    mplayerProcess->write("get_time_length\n");}void IMplayer::on_playPushButton_clicked(){    if(isPlay == 0)    {        mplayerProcess->write("pause\n");        isPlay = 1;        timeClock->start();    }}void IMplayer::on_pausePushButton_clicked(){    if(isPlay == 1)    {        mplayerProcess->write("pause\n");        //timeClock->isActive()= false;        isPlay = 0;        timeClock->stop();    }}void IMplayer::on_stopPushButton_clicked(){    timeClock->stop();    mplayerProcess->write("pausing_keep stop\n");    ui->posTimeLineEdit->setText("00:00:00");    ui->lengthTimeLineEdit->setText("00:00:00");    ui->scheduleSlider->setValue(0);    ui->voiceSlider->setValue(99);    ui->playPushButton->setDisabled(1);    ui->pausePushButton->setDisabled(1);    ui->stopPushButton->setDisabled(1);    ui->stepPushButton->setDisabled(1);    ui->backPushButton->setDisabled(1);    ui->scheduleSlider->setDisabled(1);    ui->voiceSlider->setDisabled(1);    ui->quietPushButton->setIcon(QIcon(tr(":/images/images/voice.png")));    ui->quietPushButton->setDisabled(1);}void IMplayer::on_backPushButton_clicked(){    if(timePos >= 10)    {        timePos -= 10;    }    else    {        timePos = 0;    }    mplayerProcess->write("pausing_keep seek -10 0\n");    timeClock->stop();    back_posMessage_slot();    timeClock->start();}void IMplayer::on_stepPushButton_clicked(){    if(timePos <= (timeLength - 10))    {        timePos += 10;    }    else    {        timePos = timeLength;    }    mplayerProcess->write("pausing_keep seek +10 0\n");    timeClock->stop();    back_posMessage_slot();    timeClock->start();}void IMplayer::on_quietPushButton_clicked(){    if(isMute == 1)    {        mplayerProcess->write("pausing_keep mute 0\n");        ui->quietPushButton->setIcon(QIcon(tr(":/images/images/voice.png")));        isMute = 0;    }    else    {        mplayerProcess->write("pausing_keep mute 1\n");        ui->quietPushButton->setIcon(QIcon(tr(":/images/images/quiet.png")));        isMute = 1;    }}void IMplayer::on_action_OpenFile_triggered(){    currentFileName = QFileDialog::getOpenFileName(this, tr("璇烽?鎷╁獟浣撴枃浠?quot;), tr(""),                                    tr("Video files(*.rmvb *.avi *.3gp *.mp4 *.mp3)"));    if( !currentFileName.isEmpty() )    {               this->play(currentFileName);    }}QString IMplayer::timeConversion(int timeSec){    int timeSec1 = timeSec;    QStringList ls;    ls << QString::number((unsigned int) ((timeSec1 / 3600) % 60))<< ":";    ls << QString::number((unsigned int)((timeSec1 / 60)% 60)) << ":";    ls << QString::number((unsigned int)(timeSec1 %60));    QString src = ls.join("");    QTime time1 = QTime::fromString(src, "h:m:s");    QString time2 = time1.toString();    return time2;}void IMplayer::back_Message_slot(){    while(mplayerProcess->canReadLine())    {        time = tr(mplayerProcess->readLine());    }    QStringList timeLis;    timeLis = time.split("=");    qDebug() << time.trimmed();    qDebug() << time.simplified();    QStringList::iterator it = timeLis.end();    it--;    QString leng = *it;    int timeSecLength = (int)(leng.toFloat());    QString timeSec =timeConversion(timeSecLength);    if(isLength == 1)    {        timeClock->start(1000);        QString timeLengthStr = "/";        timeLength = timeSecLength;        timeLengthStr += timeSec;        ui->lengthTimeLineEdit->setText(timeLengthStr);        timePos = 0;    }else    {        timePos = timeSecLength;        ui->posTimeLineEdit->setText(timeSec);    }}void IMplayer::back_posMessage_slot(){    isLength = 0;    mplayerProcess->write("get_time_pos\n");    //qDebug() << "abc";    //qDebug() << timeLength;    //qDebug() << ui->scheduleSlider->maximum();    int posSlider = (ui->scheduleSlider->maximum() * timePos) / timeLength;    //qDebug() << timePos;    //qDebug() << "abc";    //qDebug() << posSlider ;    ui->scheduleSlider->setValue(posSlider);    //qDebug() << timePos;}void IMplayer::on_scheduleSlider_sliderMoved(int position){    posSlider = position;    //qDebug() << "abc";    timePos = (timeLength * posSlider) / ui->scheduleSlider->maximum();    ui->posTimeLineEdit->setText(timeConversion(timePos));}void IMplayer::on_voiceSlider_sliderMoved(int position){    isMute = 0;    int posVoice = position;    int voicePos = (posVoice * 100) / ui->voiceSlider->maximum();    ui->quietPushButton->setIcon(QIcon(tr(":/images/images/voice.png")));    mplayerProcess->write(QString("volume " + QString::number(voicePos) + " 1\n" ).toUtf8());    //qDebug() << "123";}void IMplayer::on_scheduleSlider_sliderReleased(){    //qDebug() << timePos;    mplayerProcess->write(QString("seek " + QString::number(timePos) + " 2\n").toUtf8());    back_posMessage_slot();    timeClock->start();}void IMplayer::on_scheduleSlider_sliderPressed(){    timeClock->stop();}void IMplayer::on_action_OpenFile_destroyed(QObject* ){}


[解决办法]
控件命名错误 widget,因为你用的是基于widget的工程,所以在调用widget控件的时候会有一些混淆 另外,每个系统的配置不一样,区分每个系统的相关宏使用,QT 和 Mplayer都是跨平台软件 使用的时候必须注意一些不同系统下面的一些区别之处,并不是每一个方法都是用语所有的系统,看看源码

热点排行