-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtinyplayer.cpp
More file actions
79 lines (69 loc) · 1.87 KB
/
Copy pathtinyplayer.cpp
File metadata and controls
79 lines (69 loc) · 1.87 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
#include "tinyplayer.h"
#include <QFileDialog>
#include "XDemuxThread.h"
#include <QMessageBox>
static std::shared_ptr<XDemuxThread> dt = std::make_shared<XDemuxThread>();
TinyPlayer::TinyPlayer(QWidget* parent)
: QWidget(parent)
{
dt->Start();
ui.setupUi(this);
startTimer(40);
}
void TinyPlayer::timerEvent(QTimerEvent* e) {
if (isSliderPress)return;
long long total = dt->totalMs;
if (dt->totalMs > 0) {
double pos = dt->pts / (double)total;
int v = ui.playPos->maximum() * pos;
ui.playPos->setValue(v);
}
}
void TinyPlayer::OpenFile() {
dt->Start();
QString name = QFileDialog::getOpenFileName(this, QString::fromLocal8Bit("Ñ¡ÔñÊÓÆµÎļþ"));
if (name.isEmpty()) return;
this->setWindowTitle(name);
if (!dt->Open(name.toLocal8Bit(), ui.openGLWidget)) {
QMessageBox::information(0, "error", "open file failed!");
return;
}
SetPause(dt->isPause);
}
void TinyPlayer::mouseDubleClickEvent(QMouseEvent* e) {
if (isFullScreen())
this->showNormal();
else
this->showFullScreen();
}
void TinyPlayer::resizeEvent(QResizeEvent* e) {
ui.playPos->move(50, this->height() - 100);
ui.playPos->resize(this->width() - 100, ui.playPos->height());
ui.pushButton->move(100, this->height() - 150);
ui.isPlay->move(ui.pushButton->x() + ui.pushButton->width() + 10, ui.pushButton->y());
ui.openGLWidget->resize(this->size());
}
void TinyPlayer::PlayOrPause() {
bool isPause = !dt->isPause;
SetPause(isPause);
dt->SetPause(isPause);
}
void TinyPlayer::SetPause(bool isPause) {
if (isPause)
ui.isPlay->setText(QString::fromLocal8Bit("²¥ ·Å"));
else
ui.isPlay->setText(QString::fromLocal8Bit("ÔÝ Í£"));
}
void TinyPlayer::SliderPress() {
isSliderPress = true;
}
void TinyPlayer::SliderRelease() {
isSliderPress = false;
double pos = 0.0;
pos = (double)ui.playPos->value() / (double)ui.playPos->maximum();
dt->Seek(pos);
}
TinyPlayer::~TinyPlayer() {
dt->Close();
dt.reset();
}