forked from c12121234/MyFFmpegPlayer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwidget.cpp
More file actions
113 lines (100 loc) · 2.58 KB
/
widget.cpp
File metadata and controls
113 lines (100 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include "widget.h"
#include "ui_widget.h"
#include "ffmpegvideowidget.h"
#include "ffmpegdemuxthread.h"
#include <QPushButton>
#include <QFileDialog>
#include <QMessageBox>
static FFmpegDemuxThread Dt;
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
, m_bIsSliderPress(false)
{
ui->setupUi(this);
ConnectUI();
Dt.Start();
startTimer(30);
}
Widget::~Widget()
{
Dt.Close();
delete ui;
}
void Widget::timerEvent(QTimerEvent *event)
{
Q_UNUSED(event)
if(m_bIsSliderPress)
return;
long long nTotalTime = Dt.GetTotalMs();
long long nPts = Dt.GetPts();
//qDebug()<<"getPts: "<<nPts;
if(nPts>nTotalTime || llabs(nPts)>nTotalTime)
return;
if(nTotalTime>0)
{
//qDebug()<<"getPts: "<<nPts;
double dPos = (double)nPts/(double)nTotalTime;
int v = ui->horizontalSlider->maximum()*dPos;
qDebug()<<"v:"<<v;
if(v < 0)
return;
ui->horizontalSlider->setValue(v);
}
}
void Widget::SetPause(bool bIsPause)
{
if(bIsPause)
ui->BtnStart->setText("Play");
else
ui->BtnStart->setText("Pause");
}
void Widget::HandleOpenFile()
{
QString strFileName = QFileDialog::getOpenFileName(nullptr,QString::fromLocal8Bit("選擇檔案:"));
if(strFileName.isEmpty())
return;
this->setWindowTitle(strFileName);
if(!Dt.Open(strFileName.toLocal8Bit(),ui->Video))
{
QMessageBox::information(nullptr,"error","open file failed!");
return;
}
SetPause(Dt.GetPauseState());
}
void Widget::HandleBtnStartClicked()
{
bool bIsPause = !Dt.GetPauseState();
SetPause(bIsPause);
Dt.SetPause(bIsPause);
}
void Widget::HandleSliderPress()
{
m_bIsSliderPress = true;
}
void Widget::HandleSliderRelease()
{
m_bIsSliderPress = false;
double dPos = 0.0;
dPos = (double)ui->horizontalSlider->value()/(double)ui->horizontalSlider->maximum();
Dt.Seek(dPos);
}
void Widget::mouseDoubleClickEvent(QMouseEvent *event)
{
Q_UNUSED(event)
if(isFullScreen())
this->showNormal();
else
this->showFullScreen();
}
//void Widget::resizeEvent(QResizeEvent *event)
//{
// ui->Video->resize(this->size());
//}
void Widget::ConnectUI()
{
connect(ui->pushButton,&QPushButton::clicked,this,&Widget::HandleOpenFile);
connect(ui->BtnStart,&QPushButton::clicked,this,&Widget::HandleBtnStartClicked);
connect(ui->horizontalSlider,&QSlider::sliderPressed,this,&Widget::HandleSliderPress);
connect(ui->horizontalSlider,&QSlider::sliderReleased,this,&Widget::HandleSliderRelease);
}