1 | /* |
2 | * BluezQt - Asynchronous BlueZ wrapper library |
3 | * |
4 | * SPDX-FileCopyrightText: 2015 David Rosca <nowrep@gmail.com> |
5 | * |
6 | * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
7 | */ |
8 | |
9 | #ifndef BLUEZQT_MEDIAPLAYER_H |
10 | #define BLUEZQT_MEDIAPLAYER_H |
11 | |
12 | #include <QObject> |
13 | |
14 | #include "bluezqt_export.h" |
15 | #include "mediaplayertrack.h" |
16 | #include "types.h" |
17 | |
18 | #include <memory> |
19 | |
20 | namespace BluezQt |
21 | { |
22 | class PendingCall; |
23 | |
24 | /** |
25 | * @class BluezQt::MediaPlayer mediaplayer.h <BluezQt/MediaPlayer> |
26 | * |
27 | * Media player. |
28 | * |
29 | * This class represents a media player interface. |
30 | */ |
31 | class BLUEZQT_EXPORT MediaPlayer : public QObject |
32 | { |
33 | Q_OBJECT |
34 | Q_PROPERTY(QString name READ name NOTIFY nameChanged) |
35 | Q_PROPERTY(Equalizer equalizer READ equalizer WRITE setEqualizer NOTIFY equalizerChanged) |
36 | Q_PROPERTY(Repeat repeat READ repeat WRITE setRepeat NOTIFY repeatChanged) |
37 | Q_PROPERTY(Shuffle shuffle READ shuffle WRITE setShuffle NOTIFY shuffleChanged) |
38 | Q_PROPERTY(Status status READ status NOTIFY statusChanged) |
39 | Q_PROPERTY(MediaPlayerTrack track READ track NOTIFY trackChanged) |
40 | Q_PROPERTY(quint32 position READ position NOTIFY positionChanged) |
41 | |
42 | public: |
43 | /** Equalizer state. */ |
44 | enum Equalizer { |
45 | /** Equalizer on. */ |
46 | EqualizerOn, |
47 | /** Equalizer off. */ |
48 | EqualizerOff, |
49 | }; |
50 | Q_ENUM(Equalizer) |
51 | |
52 | /** Repeat state. */ |
53 | enum Repeat { |
54 | /** Repeat off. */ |
55 | RepeatOff, |
56 | /** Repeat single track. */ |
57 | RepeatSingleTrack, |
58 | /** Repeat all tracks. */ |
59 | RepeatAllTracks, |
60 | /** Repeat group. */ |
61 | RepeatGroup, |
62 | }; |
63 | Q_ENUM(Repeat) |
64 | |
65 | /** Shuffle state. */ |
66 | enum Shuffle { |
67 | /** Shuffle off. */ |
68 | ShuffleOff, |
69 | /** Shuffle all tracks. */ |
70 | ShuffleAllTracks, |
71 | /** Shuffle group. */ |
72 | ShuffleGroup, |
73 | }; |
74 | Q_ENUM(Shuffle) |
75 | |
76 | /** Player status. */ |
77 | enum Status { |
78 | /** Player is playing. */ |
79 | Playing, |
80 | /** Player is stopped. */ |
81 | Stopped, |
82 | /** Player is paused. */ |
83 | Paused, |
84 | /** Player is forward seeking. */ |
85 | ForwardSeek, |
86 | /** Player is reverse seeking. */ |
87 | ReverseSeek, |
88 | /** Error */ |
89 | Error, |
90 | }; |
91 | Q_ENUM(Status) |
92 | |
93 | /** |
94 | * Destroys a MediaPlayer object. |
95 | */ |
96 | ~MediaPlayer() override; |
97 | |
98 | /** |
99 | * Returns a shared pointer from this. |
100 | * |
101 | * @return MediaPlayerPtr |
102 | */ |
103 | MediaPlayerPtr toSharedPtr() const; |
104 | |
105 | /** |
106 | * Returns the name of the player. |
107 | * |
108 | * @return name of player |
109 | */ |
110 | QString name() const; |
111 | |
112 | /** |
113 | * Returns the equalizer state of the player. |
114 | * |
115 | * @return equalizer state of player |
116 | */ |
117 | Equalizer equalizer() const; |
118 | |
119 | /** |
120 | * Sets the equalizer state of the player. |
121 | * |
122 | * @param equalizer equalizer state |
123 | * @return void pending call |
124 | */ |
125 | PendingCall *setEqualizer(Equalizer equalizer); |
126 | |
127 | /** |
128 | * Returns the repeat state of the player. |
129 | * |
130 | * @return repeat state of player |
131 | */ |
132 | Repeat repeat() const; |
133 | |
134 | /** |
135 | * Sets the repeat state of the player. |
136 | * |
137 | * @param repeat repeat state |
138 | * @return void pending call |
139 | */ |
140 | PendingCall *setRepeat(Repeat repeat); |
141 | |
142 | /** |
143 | * Returns the shuffle state of the player. |
144 | * |
145 | * @return shuffle state of player |
146 | */ |
147 | Shuffle shuffle() const; |
148 | |
149 | /** |
150 | * Sets the shuffle state of the player. |
151 | * |
152 | * @param shuffle shuffle state |
153 | * @return void pending call |
154 | */ |
155 | PendingCall *setShuffle(Shuffle shuffle); |
156 | |
157 | /** |
158 | * Returns the status of the player. |
159 | * |
160 | * @return status of player |
161 | */ |
162 | Status status() const; |
163 | |
164 | /** |
165 | * Returns the current track. |
166 | * |
167 | * @return current track |
168 | */ |
169 | MediaPlayerTrack track() const; |
170 | |
171 | /** |
172 | * Returns the playback position in milliseconds. |
173 | * |
174 | * @return playback position |
175 | */ |
176 | quint32 position() const; |
177 | |
178 | public Q_SLOTS: |
179 | /** |
180 | * Resumes playback. |
181 | * |
182 | * Possible errors: PendingCall::NotSupported, PendingCall::Failed |
183 | * |
184 | * @return void pending call |
185 | */ |
186 | PendingCall *play(); |
187 | |
188 | /** |
189 | * Pauses playback. |
190 | * |
191 | * Possible errors: PendingCall::NotSupported, PendingCall::Failed |
192 | * |
193 | * @return void pending call |
194 | */ |
195 | PendingCall *pause(); |
196 | |
197 | /** |
198 | * Stops playback. |
199 | * |
200 | * Possible errors: PendingCall::NotSupported, PendingCall::Failed |
201 | * |
202 | * @return void pending call |
203 | */ |
204 | PendingCall *stop(); |
205 | |
206 | /** |
207 | * Switch to next track. |
208 | * |
209 | * Possible errors: PendingCall::NotSupported, PendingCall::Failed |
210 | * |
211 | * @return void pending call |
212 | */ |
213 | PendingCall *next(); |
214 | |
215 | /** |
216 | * Switch to previous track. |
217 | * |
218 | * Possible errors: PendingCall::NotSupported, PendingCall::Failed |
219 | * |
220 | * @return void pending call |
221 | */ |
222 | PendingCall *previous(); |
223 | |
224 | /** |
225 | * Fast forwards playback. |
226 | * |
227 | * Possible errors: PendingCall::NotSupported, PendingCall::Failed |
228 | * |
229 | * @return void pending call |
230 | */ |
231 | PendingCall *fastForward(); |
232 | |
233 | /** |
234 | * Rewinds playback. |
235 | * |
236 | * Possible errors: PendingCall::NotSupported, PendingCall::Failed |
237 | * |
238 | * @return void pending call |
239 | */ |
240 | PendingCall *rewind(); |
241 | |
242 | Q_SIGNALS: |
243 | /** |
244 | * Indicates that player's name have changed. |
245 | */ |
246 | void nameChanged(const QString &name); |
247 | |
248 | /** |
249 | * Indicates that player's equalizer state have changed. |
250 | */ |
251 | void equalizerChanged(Equalizer equalizer); |
252 | |
253 | /** |
254 | * Indicates that player's repeat state have changed. |
255 | */ |
256 | void repeatChanged(Repeat repeat); |
257 | |
258 | /** |
259 | * Indicates that player's shuffle state have changed. |
260 | */ |
261 | void shuffleChanged(Shuffle shuffle); |
262 | |
263 | /** |
264 | * Indicates that player's status have changed. |
265 | */ |
266 | void statusChanged(Status status); |
267 | |
268 | /** |
269 | * Indicates that player's current track have changed. |
270 | */ |
271 | void trackChanged(MediaPlayerTrack track); |
272 | |
273 | /** |
274 | * Indicates that player's playback position have changed. |
275 | */ |
276 | void positionChanged(quint32 position); |
277 | |
278 | private: |
279 | BLUEZQT_NO_EXPORT explicit MediaPlayer(const QString &path, const QVariantMap &properties); |
280 | |
281 | std::unique_ptr<class MediaPlayerPrivate> const d; |
282 | |
283 | friend class MediaPlayerPrivate; |
284 | friend class DevicePrivate; |
285 | }; |
286 | |
287 | } // namespace BluezQt |
288 | |
289 | #endif // BLUEZQT_MEDIAPLAYER_H |
290 | |