在unbunto qtcreate中定时器是否会影响视频播放?
今天做了个简易视频播放。遇到个问题,当播放视频时,视频中间会时不时出现黑框。这是否跟我做了定时器有关?如果是,那应该如何解决?(定时器用来获取播放时间)。望各位大神帮帮忙!代码如下
#include "phonon_indie.h"
#include "ui_phonon_indie.h"
#include <QTime>
#include<QTimer>
#include<Q_INT64>
#include<QVBoxLayout>
#include<QHBoxLayout>
Phonon_Indie::Phonon_Indie(QWidget *parent) :
QWidget(parent),
ui(new Ui::Phonon_Indie)
{
ui->setupUi(this);
media=new Phonon::MediaObject(this);
videowidget = new Phonon::VideoWidget(this);
Phonon::createPath(media,videowidget);
Phonon::AudioOutput *audio= new Phonon::AudioOutput(Phonon::VideoCategory,this);
Phonon::createPath(media,audio);
media->setCurrentSource(Phonon::MediaSource("../phonon_indie/myVideo.WMV"));
videowidget->move(9,9);
videowidget->resize(381,141);
//创建媒体的窗口
Phonon::SeekSlider *seekSlider= new Phonon::SeekSlider(media,this);
seekSlider->move(0,150);
seekSlider->resize(401,31);
//创建滑动条
QVBoxLayout *vboxlayout=new QVBoxLayout;
vboxlayout->addWidget(videowidget);
vboxlayout->addWidget(seekSlider);
QHBoxLayout *hboxlayout=new QHBoxLayout;
hboxlayout->addWidget(ui->PlayButton);
hboxlayout->addWidget(ui->lineEdit);
hboxlayout->addWidget(ui->time_label);
vboxlayout->addLayout(hboxlayout);
setLayout(vboxlayout);
//创建布局管理器
QTimer *timer=new QTimer(this);
connect(timer,SIGNAL(timeout()),this,SLOT(timeUpdate()));
timer->start(1000);//1 second
//创建定时器
}
Phonon_Indie::~Phonon_Indie()
{
delete ui;
}
void Phonon_Indie::timeUpdate()
{
// nowtime=ui->videoPlayer->currentTime();
qint64 total_time_value = media->totalTime();//直接获取该音频文件的总时长参数,单位为毫秒
//这3个参数分别代表了时,分,秒;60000毫秒为1分钟,所以分钟第二个参数是先除6000,第3个参数是直接除1s
time =media->currentTime();
QTime total_time(0, (total_time_value/60000)%60, (total_time_value/1000)%60);
QTime current_time(0, (time/60000)%60, (time/1000)%60);//传进来的time参数代表了当前的时间
QString str = current_time.toString("mm:ss") + "/" + total_time.toString("mm:ss");
ui->time_label->setText(str);
}
//定时器函数
void Phonon_Indie::on_PlayButton_clicked()
{
media->play();
}