BluezQt

mediaplayer.cpp
1 /*
2  * BluezQt - Asynchronous Bluez wrapper library
3  *
4  * SPDX-FileCopyrightText: 2015 David Rosca <[email protected]>
5  *
6  * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
7  */
8 
9 #include "mediaplayer.h"
10 #include "mediaplayer_p.h"
11 #include "pendingcall.h"
12 
13 namespace BluezQt
14 {
15 static QString equalizerToString(MediaPlayer::Equalizer equalizer)
16 {
17  switch (equalizer) {
19  return QStringLiteral("on");
20  default:
21  return QStringLiteral("off");
22  }
23 }
24 
25 static QString repeatToString(MediaPlayer::Repeat repeat)
26 {
27  switch (repeat) {
29  return QStringLiteral("singletrack");
31  return QStringLiteral("alltracks");
33  return QStringLiteral("group");
34  default:
35  return QStringLiteral("off");
36  }
37 }
38 
39 static QString shuffleToString(MediaPlayer::Shuffle shuffle)
40 {
41  switch (shuffle) {
43  return QStringLiteral("alltracks");
45  return QStringLiteral("group");
46  default:
47  return QStringLiteral("off");
48  }
49 }
50 
51 MediaPlayer::MediaPlayer(const QString &path, const QVariantMap &properties)
52  : QObject()
53  , d(new MediaPlayerPrivate(path, properties))
54 {
55 }
56 
58 {
59  delete d;
60 }
61 
63 {
64  return d->q.toStrongRef();
65 }
66 
67 QString MediaPlayer::name() const
68 {
69  return d->m_name;
70 }
71 
72 MediaPlayer::Equalizer MediaPlayer::equalizer() const
73 {
74  return d->m_equalizer;
75 }
76 
78 {
79  return new PendingCall(d->setDBusProperty(QStringLiteral("Equalizer"), equalizerToString(equalizer)), PendingCall::ReturnVoid, this);
80 }
81 
82 MediaPlayer::Repeat MediaPlayer::repeat() const
83 {
84  return d->m_repeat;
85 }
86 
88 {
89  return new PendingCall(d->setDBusProperty(QStringLiteral("Repeat"), repeatToString(repeat)), PendingCall::ReturnVoid, this);
90 }
91 
92 MediaPlayer::Shuffle MediaPlayer::shuffle() const
93 {
94  return d->m_shuffle;
95 }
96 
98 {
99  return new PendingCall(d->setDBusProperty(QStringLiteral("Shuffle"), shuffleToString(shuffle)), PendingCall::ReturnVoid, this);
100 }
101 
102 MediaPlayer::Status MediaPlayer::status() const
103 {
104  return d->m_status;
105 }
106 
107 MediaPlayerTrack MediaPlayer::track() const
108 {
109  return d->m_track;
110 }
111 
112 quint32 MediaPlayer::position() const
113 {
114  return d->m_position;
115 }
116 
118 {
119  return new PendingCall(d->m_bluezMediaPlayer->Play(), PendingCall::ReturnVoid, this);
120 }
121 
123 {
124  return new PendingCall(d->m_bluezMediaPlayer->Pause(), PendingCall::ReturnVoid, this);
125 }
126 
128 {
129  return new PendingCall(d->m_bluezMediaPlayer->Stop(), PendingCall::ReturnVoid, this);
130 }
131 
133 {
134  return new PendingCall(d->m_bluezMediaPlayer->Next(), PendingCall::ReturnVoid, this);
135 }
136 
138 {
139  return new PendingCall(d->m_bluezMediaPlayer->Previous(), PendingCall::ReturnVoid, this);
140 }
141 
143 {
144  return new PendingCall(d->m_bluezMediaPlayer->FastForward(), PendingCall::ReturnVoid, this);
145 }
146 
148 {
149  return new PendingCall(d->m_bluezMediaPlayer->Rewind(), PendingCall::ReturnVoid, this);
150 }
151 
152 } // namespace BluezQt
PendingCall * pause()
Pauses playback.
Equalizer
Equalizer state.
Definition: mediaplayer.h:42
KGuiItem properties()
@ RepeatGroup
Repeat group.
Definition: mediaplayer.h:59
@ RepeatAllTracks
Repeat all tracks.
Definition: mediaplayer.h:57
PendingCall * setEqualizer(Equalizer equalizer)
Sets the equalizer state of the player.
Definition: mediaplayer.cpp:77
PendingCall * setShuffle(Shuffle shuffle)
Sets the shuffle state of the player.
Definition: mediaplayer.cpp:97
@ ShuffleAllTracks
Shuffle all tracks.
Definition: mediaplayer.h:68
@ RepeatSingleTrack
Repeat single track.
Definition: mediaplayer.h:55
PendingCall * stop()
Stops playback.
Repeat
Repeat state.
Definition: mediaplayer.h:51
MediaPlayerPtr toSharedPtr() const
Returns a shared pointer from this.
Definition: mediaplayer.cpp:62
PendingCall * rewind()
Rewinds playback.
~MediaPlayer() override
Destroys a MediaPlayer object.
Definition: mediaplayer.cpp:57
@ ShuffleGroup
Shuffle group.
Definition: mediaplayer.h:70
PendingCall * next()
Switch to next track.
@ EqualizerOn
Equalizer on.
Definition: mediaplayer.h:44
Shuffle
Shuffle state.
Definition: mediaplayer.h:64
PendingCall * setRepeat(Repeat repeat)
Sets the repeat state of the player.
Definition: mediaplayer.cpp:87
PendingCall * play()
Resumes playback.
PendingCall * previous()
Switch to previous track.
Status
Player status.
Definition: mediaplayer.h:75
PendingCall * fastForward()
Fast forwards playback.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sun Sep 25 2022 04:19:10 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.