This repository has been archived by the owner on Apr 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer_window.cpp
143 lines (118 loc) · 3.49 KB
/
player_window.cpp
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
Copyright (C) 2010 George Kiagiadakis <[email protected]>
Copyright (C) 2010 Brandon Lewis <[email protected]>
This library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "player_window.h"
#include <QGst/enums.h>
#include <QString>
static int clockTimeToInt(quint64 time)
{
return int(time >> 32);
}
static quint64 clockTimeFromInt(int time)
{
return quint64(time) << 32;
}
class SeekingSlider : public QSlider
{
};
PlayerWindow::PlayerWindow(Player * player)
{
m_player = player;
createUi();
}
void PlayerWindow::createUi()
{
vbox = new QVBoxLayout ();
hbox = new QHBoxLayout ();
vbox->addLayout(hbox);
setLayout(vbox);
play_pause = new QPushButton("Play");
hbox->addWidget(play_pause);
hbox->addStretch(0);
info = new QLabel();
hbox->addWidget(info);
position = new SeekingSlider();
position->setTracking(false);
position->setOrientation(Qt::Horizontal);
position->setMinimum(0);
position->setMaximum(0);
vbox->addWidget(position);
resize(320, 75);
show();
connect(m_player, SIGNAL(durationChanged(quint64)),
this, SLOT(durationChanged(quint64)));
connect(m_player, SIGNAL(stateChanged(QGst::State)),
this, SLOT(stateChanged(QGst::State)));
connect(m_player, SIGNAL(positionChanged(quint64)),
this, SLOT(positionChanged(quint64)));
connect(play_pause, SIGNAL(clicked(bool)),
this, SLOT(playButtonClicked(bool)));
connect(position, SIGNAL(sliderMoved(int)),
this, SLOT(sliderMoved(int)));
durationChanged(-1);
positionChanged(-1);
}
void PlayerWindow::stateChanged(QGst::State state)
{
qDebug() << "State changed" << state;
switch (state) {
case QGst::StatePlaying:
play_pause->setText("Pause");
break;
default:
play_pause->setText("Play");
break;
}
}
void PlayerWindow::positionChanged(quint64 pos)
{
position->setSliderPosition(clockTimeToInt(pos));
cur_pos = pos;
updateDisplay();
}
void PlayerWindow::updateDisplay() {
QString pos_str ("--:--:--");
QString dur_str ("--:--:--");
if (cur_pos != -1) {
pos_str = QGst::Clock::timeFromClockTime(cur_pos).toString();
}
if (duration != -1) {
dur_str = QGst::Clock::timeFromClockTime(duration).toString();
}
info->setText(pos_str + " / " + dur_str);
}
void PlayerWindow::durationChanged(quint64 duration)
{
qDebug() << "Duration changed" <<
QGst::Clock::timeFromClockTime(duration);
// should use QGst::ClockTimeNone, but it was not present in the library
if (!((duration == -1) || (duration == 0))) {
position->setMaximum(clockTimeToInt(duration));
}
this->duration = duration;
updateDisplay();
}
void PlayerWindow::playButtonClicked(bool checked)
{
qDebug() << "Playing pipeline";
if (m_player->state() == QGst::StatePlaying) {
m_player->pause();
} else {
m_player->play();
}
}
void PlayerWindow::sliderMoved(int value)
{
m_player->setPosition(clockTimeFromInt(value));
}