Skip to content

Commit 604135e

Browse files
committed
Mpris: implement some basic player comments
1 parent 880122e commit 604135e

3 files changed

Lines changed: 69 additions & 11 deletions

File tree

src/mpris/mediaplayer2player.cpp

Lines changed: 66 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
11
#include <QApplication>
22

3+
#include "playerinfo.h"
4+
#include "playermanager.h"
5+
#include "controlobject.h"
6+
37
#include "mediaplayer2player.h"
48

9+
static const char* kPlaybackStatusPlaying = "Playing";
10+
static const char* kPlaybackStatusPaused = "Paused";
11+
static const char* kPlaybackStatusStopped = "Stopped";
12+
13+
// the playback will stop when there are no more tracks to play
14+
static const char* kLoopStatusNone = "None";
15+
// The current track will start again from the begining once it has finished playing
16+
static const char* kLoopStatusTrack = "Track";
17+
// The playback loops through a list of tracks
18+
static const char* kLoopStatusPlaylist = "Playlist";
19+
20+
521
MediaPlayer2Player::MediaPlayer2Player(QObject *parent)
622
: QDBusAbstractAdaptor(parent) {
723
}
@@ -10,21 +26,48 @@ MediaPlayer2Player::~MediaPlayer2Player() {
1026
}
1127

1228
QString MediaPlayer2Player::playbackStatus() const {
13-
QString playbackStatus;
14-
return playbackStatus;
29+
TrackPointer pTrack;
30+
pTrack = PlayerInfo::instance().getCurrentPlayingTrack();
31+
if (!pTrack.isNull()) {
32+
return QString(kPlaybackStatusPlaying);
33+
} else {
34+
// TODO: Decide how to handle the mpris Pause state
35+
return QString(kPlaybackStatusStopped);
36+
}
1537
}
1638

1739
QString MediaPlayer2Player::loopStatus() const {
18-
QString loopStatus;
19-
return loopStatus;
40+
TrackPointer pTrack;
41+
int deckIndex = PlayerInfo::instance().getCurrentPlayingDeck();
42+
if (deckIndex >= 0) {
43+
QString group = PlayerManager::groupForDeck(deckIndex);
44+
ConfigKey key(group, "repeat");
45+
if (ControlObject::get(key) > 0.0) {
46+
return QString(kLoopStatusTrack);
47+
}
48+
// TODO: Decide when how to Handle playlist repeat mode
49+
}
50+
return QString(kLoopStatusNone);
2051
}
2152

2253
void MediaPlayer2Player::setLoopStatus(const QString& value) {
23-
Q_UNUSED(value);
54+
double repeat = 0.0;
55+
if (value == kLoopStatusTrack) {
56+
repeat = 1.0;
57+
}
58+
59+
TrackPointer pTrack;
60+
int deckIndex = PlayerInfo::instance().getCurrentPlayingDeck();
61+
if (deckIndex >= 0) {
62+
QString group = PlayerManager::groupForDeck(deckIndex);
63+
ConfigKey key(group, "repeat");
64+
ControlObject::set(key, repeat);
65+
// TODO: Decide when how to handle playlist repeat mode
66+
}
2467
}
2568

2669
double MediaPlayer2Player::rate() const {
27-
double rate = 0.0;
70+
double rate = 1.0;
2871
return rate;
2972
}
3073

@@ -61,11 +104,11 @@ qlonglong MediaPlayer2Player::position() const {
61104
}
62105

63106
double MediaPlayer2Player::minimumRate() const {
64-
return 0.0;
107+
return 1.0;
65108
}
66109

67110
double MediaPlayer2Player::maximumRate() const {
68-
return 0.0;
111+
return 1.0;
69112
}
70113

71114
bool MediaPlayer2Player::canGoNext() const {
@@ -81,7 +124,7 @@ bool MediaPlayer2Player::canPlay() const {
81124
}
82125

83126
bool MediaPlayer2Player::canPause() const {
84-
return false;
127+
return true;
85128
}
86129

87130
bool MediaPlayer2Player::canSeek() const {
@@ -99,12 +142,26 @@ void MediaPlayer2Player::Previous() {
99142
}
100143

101144
void MediaPlayer2Player::Pause() {
145+
TrackPointer pTrack;
146+
int deckIndex = PlayerInfo::instance().getCurrentPlayingDeck();
147+
if (deckIndex >= 0) {
148+
QString group = PlayerManager::groupForDeck(deckIndex);
149+
ConfigKey key(group, "play");
150+
ControlObject::set(key, 0.0);
151+
}
102152
}
103153

104154
void MediaPlayer2Player::PlayPause() {
105155
}
106156

107157
void MediaPlayer2Player::Stop() {
158+
TrackPointer pTrack;
159+
int deckIndex = PlayerInfo::instance().getCurrentPlayingDeck();
160+
if (deckIndex >= 0) {
161+
QString group = PlayerManager::groupForDeck(deckIndex);
162+
ConfigKey key(group, "play");
163+
ControlObject::set(key, 0.0);
164+
}
108165
}
109166

110167
void MediaPlayer2Player::Play() {

src/playerinfo.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ void PlayerInfo::updateCurrentPlayingDeck() {
159159
}
160160

161161
int PlayerInfo::getCurrentPlayingDeck() {
162-
QMutexLocker locker(&m_mutex);
162+
// no need to lock m_mutex, because reading
163+
// m_currentlyPlayingDeck is already atomic
163164
return m_currentlyPlayingDeck;
164165
}
165166

src/playerinfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class PlayerInfo : public QObject {
3333
TrackPointer getTrackInfo(const QString& group);
3434
void setTrackInfo(const QString& group, const TrackPointer& trackInfoObj);
3535
TrackPointer getCurrentPlayingTrack();
36+
int getCurrentPlayingDeck();
3637
QMap<QString, TrackPointer> getLoadedTracks();
3738
bool isTrackLoaded(const TrackPointer& pTrack) const;
3839
bool isFileLoaded(const QString& track_location) const;
@@ -62,7 +63,6 @@ class PlayerInfo : public QObject {
6263
void clearControlCache();
6364
void timerEvent(QTimerEvent* pTimerEvent);
6465
void updateCurrentPlayingDeck();
65-
int getCurrentPlayingDeck();
6666
DeckControls* getDeckControls(int i);
6767

6868
PlayerInfo();

0 commit comments

Comments
 (0)