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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
#include <QMetaEnum>
#include "qmpcorepublic.hpp"
#include "../qmidiplayer-desktop/qmpmainwindow.hpp"
#include "qmpmprisimpl.hpp"
inline QVariantMap get_metadata(qmpPluginAPI *api)
{
::PlaybackStatus ps = api->getPlaybackStatus();
return {
{"mpris:trackid", QDBusObjectPath("/org/chrisoft/qmidiplayer/dummylist/0")},
{"xesam:url", QString::fromStdWString(api->getWFilePath())},
{"xesam:title", QString::fromStdWString(api->getWTitle())},
{"mpris:length", qlonglong(ps.maxtime_ms * 1000)}
};
}
QMPPlayer::QMPPlayer(qmpPluginAPI *_api, QObject *parent) :
api(_api),
QMPrisPlayer(parent)
{
qmw = static_cast<qmpMainWindow*>(api->getMainWindow());
}
QString QMPPlayer::getPlaybackStatus()
{
::PlaybackStatus ps = api->getPlaybackStatus();
QMPrisPlayer::PlaybackStatus r = QMPrisPlayer::PlaybackStatus::Stopped;
if (!ps.stopped)
r = ps.paused ? QMPrisPlayer::PlaybackStatus::Paused : QMPrisPlayer::PlaybackStatus::Playing;
return QMetaEnum::fromType<QMPrisPlayer::PlaybackStatus>().key(r);
}
QString QMPPlayer::getLoopStatus()
{
return QMetaEnum::fromType<QMPrisPlayer::LoopStatus>().key(QMPrisPlayer::LoopStatus::None);
}
double QMPPlayer::getRate()
{
return 1;
}
bool QMPPlayer::getShuffle()
{
return false;
}
QVariantMap QMPPlayer::getMetadata()
{
::PlaybackStatus ps = api->getPlaybackStatus();
if (ps.stopped) return {};
return get_metadata(api);
}
qlonglong QMPPlayer::getPosition()
{
::PlaybackStatus ps = api->getPlaybackStatus();
return ps.curtime_ms * 1000;
}
bool QMPPlayer::getCanGoNext()
{
return getCanPlay();
}
bool QMPPlayer::getCanGoPrevious()
{
return getCanPlay();
}
bool QMPPlayer::getCanPlay()
{
::PlaybackStatus ps = api->getPlaybackStatus();
return !ps.stopped;
}
bool QMPPlayer::getCanPause()
{
::PlaybackStatus ps = api->getPlaybackStatus();
return !ps.stopped && !ps.paused;
}
bool QMPPlayer::getCanSeek()
{
return getCanPlay();
}
bool QMPPlayer::getCanControl()
{
return true;
}
void QMPPlayer::Pause()
{
api->playbackControl(PlaybackControlCommand::Pause, nullptr);
}
void QMPPlayer::PlayPause()
{
api->playbackControl(PlaybackControlCommand::TogglePause, nullptr);
}
void QMPPlayer::Stop()
{
api->playbackControl(PlaybackControlCommand::Stop, nullptr);
}
void QMPPlayer::Play()
{
api->playbackControl(PlaybackControlCommand::Play, nullptr);
}
void QMPPlayer::Next()
{
api->playbackControl(PlaybackControlCommand::NextTrack, nullptr);
}
void QMPPlayer::Previous()
{
api->playbackControl(PlaybackControlCommand::PrevTrack, nullptr);
}
void QMPPlayer::Seek(qlonglong t)
{
double td = t / 1e6;
api->playbackControl(PlaybackControlCommand::SeekAbs, &td);
}
void QMPPlayer::SetPosition(QDBusObjectPath o, qlonglong t)
{
if (o.path() == QString("/org/chrisoft/qmidiplayer/dummylist/0"))
{
double td = t / 1e6;
api->playbackControl(PlaybackControlCommand::SeekAbs, &td);
}
}
QMPMediaPlayer2::QMPMediaPlayer2(qmpPluginAPI *_api, QObject *parent) :
api(_api),
QMPrisMediaPlayer2(parent)
{
qmw = static_cast<qmpMainWindow*>(api->getMainWindow());
}
void QMPMediaPlayer2::Raise()
{
qmw->raise();
}
void QMPMediaPlayer2::Quit()
{
qmw->close();
}
bool QMPMediaPlayer2::getCanQuit()
{
return true;
}
bool QMPMediaPlayer2::getCanRaise()
{
return true;
}
QString QMPMediaPlayer2::getIdentity()
{
return QString("QMidiPlayer");
}
QString QMPMediaPlayer2::getDesktopEntry()
{
return QString("qmidiplayer");
}
bool QMPMediaPlayer2::getHasTrackList()
{
return true;
}
QMPTrackList::QMPTrackList(qmpPluginAPI *_api, QObject *parent) :
api(_api),
QMPrisTrackList(parent)
{
}
QList<QVariantMap> QMPTrackList::GetTracksMetaData(QList<QDBusObjectPath> trackIds)
{
QList<QVariantMap> ret;
for (auto &i : trackIds)
{
if (i.path() == QString("/org/chrisoft/qmidiplayer/dummylist/0"))
ret.push_back(get_metadata(api));
else ret.push_back({});
}
return ret;
}
QList<QDBusObjectPath> QMPTrackList::getTracks()
{
::PlaybackStatus ps = api->getPlaybackStatus();
if (ps.stopped)
return {};
return {QDBusObjectPath("/org/chrisoft/qmidiplayer/dummylist/0")};
}
|