File indexing completed on 2024-05-05 03:52:31

0001 /*
0002  * BluezQt - Asynchronous BlueZ wrapper library
0003  *
0004  * SPDX-FileCopyrightText: 2015 David Rosca <nowrep@gmail.com>
0005  *
0006  * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007  */
0008 
0009 #ifndef BLUEZQT_MEDIAPLAYER_H
0010 #define BLUEZQT_MEDIAPLAYER_H
0011 
0012 #include <QObject>
0013 
0014 #include "bluezqt_export.h"
0015 #include "mediaplayertrack.h"
0016 #include "types.h"
0017 
0018 #include <memory>
0019 
0020 namespace BluezQt
0021 {
0022 class PendingCall;
0023 
0024 /**
0025  * @class BluezQt::MediaPlayer mediaplayer.h <BluezQt/MediaPlayer>
0026  *
0027  * Media player.
0028  *
0029  * This class represents a media player interface.
0030  */
0031 class BLUEZQT_EXPORT MediaPlayer : public QObject
0032 {
0033     Q_OBJECT
0034     Q_PROPERTY(QString name READ name NOTIFY nameChanged)
0035     Q_PROPERTY(Equalizer equalizer READ equalizer WRITE setEqualizer NOTIFY equalizerChanged)
0036     Q_PROPERTY(Repeat repeat READ repeat WRITE setRepeat NOTIFY repeatChanged)
0037     Q_PROPERTY(Shuffle shuffle READ shuffle WRITE setShuffle NOTIFY shuffleChanged)
0038     Q_PROPERTY(Status status READ status NOTIFY statusChanged)
0039     Q_PROPERTY(MediaPlayerTrack track READ track NOTIFY trackChanged)
0040     Q_PROPERTY(quint32 position READ position NOTIFY positionChanged)
0041 
0042 public:
0043     /** Equalizer state. */
0044     enum Equalizer {
0045         /** Equalizer on. */
0046         EqualizerOn,
0047         /** Equalizer off. */
0048         EqualizerOff,
0049     };
0050     Q_ENUM(Equalizer)
0051 
0052     /** Repeat state. */
0053     enum Repeat {
0054         /** Repeat off. */
0055         RepeatOff,
0056         /** Repeat single track. */
0057         RepeatSingleTrack,
0058         /** Repeat all tracks. */
0059         RepeatAllTracks,
0060         /** Repeat group. */
0061         RepeatGroup,
0062     };
0063     Q_ENUM(Repeat)
0064 
0065     /** Shuffle state. */
0066     enum Shuffle {
0067         /** Shuffle off. */
0068         ShuffleOff,
0069         /** Shuffle all tracks. */
0070         ShuffleAllTracks,
0071         /** Shuffle group. */
0072         ShuffleGroup,
0073     };
0074     Q_ENUM(Shuffle)
0075 
0076     /** Player status. */
0077     enum Status {
0078         /** Player is playing. */
0079         Playing,
0080         /** Player is stopped. */
0081         Stopped,
0082         /** Player is paused. */
0083         Paused,
0084         /** Player is forward seeking. */
0085         ForwardSeek,
0086         /** Player is reverse seeking. */
0087         ReverseSeek,
0088         /** Error */
0089         Error,
0090     };
0091     Q_ENUM(Status)
0092 
0093     /**
0094      * Destroys a MediaPlayer object.
0095      */
0096     ~MediaPlayer() override;
0097 
0098     /**
0099      * Returns a shared pointer from this.
0100      *
0101      * @return MediaPlayerPtr
0102      */
0103     MediaPlayerPtr toSharedPtr() const;
0104 
0105     /**
0106      * Returns the name of the player.
0107      *
0108      * @return name of player
0109      */
0110     QString name() const;
0111 
0112     /**
0113      * Returns the equalizer state of the player.
0114      *
0115      * @return equalizer state of player
0116      */
0117     Equalizer equalizer() const;
0118 
0119     /**
0120      * Sets the equalizer state of the player.
0121      *
0122      * @param equalizer equalizer state
0123      * @return void pending call
0124      */
0125     PendingCall *setEqualizer(Equalizer equalizer);
0126 
0127     /**
0128      * Returns the repeat state of the player.
0129      *
0130      * @return repeat state of player
0131      */
0132     Repeat repeat() const;
0133 
0134     /**
0135      * Sets the repeat state of the player.
0136      *
0137      * @param repeat repeat state
0138      * @return void pending call
0139      */
0140     PendingCall *setRepeat(Repeat repeat);
0141 
0142     /**
0143      * Returns the shuffle state of the player.
0144      *
0145      * @return shuffle state of player
0146      */
0147     Shuffle shuffle() const;
0148 
0149     /**
0150      * Sets the shuffle state of the player.
0151      *
0152      * @param shuffle shuffle state
0153      * @return void pending call
0154      */
0155     PendingCall *setShuffle(Shuffle shuffle);
0156 
0157     /**
0158      * Returns the status of the player.
0159      *
0160      * @return status of player
0161      */
0162     Status status() const;
0163 
0164     /**
0165      * Returns the current track.
0166      *
0167      * @return current track
0168      */
0169     MediaPlayerTrack track() const;
0170 
0171     /**
0172      * Returns the playback position in milliseconds.
0173      *
0174      * @return playback position
0175      */
0176     quint32 position() const;
0177 
0178 public Q_SLOTS:
0179     /**
0180      * Resumes playback.
0181      *
0182      * Possible errors: PendingCall::NotSupported, PendingCall::Failed
0183      *
0184      * @return void pending call
0185      */
0186     PendingCall *play();
0187 
0188     /**
0189      * Pauses playback.
0190      *
0191      * Possible errors: PendingCall::NotSupported, PendingCall::Failed
0192      *
0193      * @return void pending call
0194      */
0195     PendingCall *pause();
0196 
0197     /**
0198      * Stops playback.
0199      *
0200      * Possible errors: PendingCall::NotSupported, PendingCall::Failed
0201      *
0202      * @return void pending call
0203      */
0204     PendingCall *stop();
0205 
0206     /**
0207      * Switch to next track.
0208      *
0209      * Possible errors: PendingCall::NotSupported, PendingCall::Failed
0210      *
0211      * @return void pending call
0212      */
0213     PendingCall *next();
0214 
0215     /**
0216      * Switch to previous track.
0217      *
0218      * Possible errors: PendingCall::NotSupported, PendingCall::Failed
0219      *
0220      * @return void pending call
0221      */
0222     PendingCall *previous();
0223 
0224     /**
0225      * Fast forwards playback.
0226      *
0227      * Possible errors: PendingCall::NotSupported, PendingCall::Failed
0228      *
0229      * @return void pending call
0230      */
0231     PendingCall *fastForward();
0232 
0233     /**
0234      * Rewinds playback.
0235      *
0236      * Possible errors: PendingCall::NotSupported, PendingCall::Failed
0237      *
0238      * @return void pending call
0239      */
0240     PendingCall *rewind();
0241 
0242 Q_SIGNALS:
0243     /**
0244      * Indicates that player's name have changed.
0245      */
0246     void nameChanged(const QString &name);
0247 
0248     /**
0249      * Indicates that player's equalizer state have changed.
0250      */
0251     void equalizerChanged(Equalizer equalizer);
0252 
0253     /**
0254      * Indicates that player's repeat state have changed.
0255      */
0256     void repeatChanged(Repeat repeat);
0257 
0258     /**
0259      * Indicates that player's shuffle state have changed.
0260      */
0261     void shuffleChanged(Shuffle shuffle);
0262 
0263     /**
0264      * Indicates that player's status have changed.
0265      */
0266     void statusChanged(Status status);
0267 
0268     /**
0269      * Indicates that player's current track have changed.
0270      */
0271     void trackChanged(MediaPlayerTrack track);
0272 
0273     /**
0274      * Indicates that player's playback position have changed.
0275      */
0276     void positionChanged(quint32 position);
0277 
0278 private:
0279     BLUEZQT_NO_EXPORT explicit MediaPlayer(const QString &path, const QVariantMap &properties);
0280 
0281     std::unique_ptr<class MediaPlayerPrivate> const d;
0282 
0283     friend class MediaPlayerPrivate;
0284     friend class DevicePrivate;
0285 };
0286 
0287 } // namespace BluezQt
0288 
0289 #endif // BLUEZQT_MEDIAPLAYER_H