File indexing completed on 2024-04-21 04:48:54

0001 /*
0002    SPDX-FileCopyrightText: 2017 (c) Matthieu Gallien <matthieu_gallien@yahoo.fr>
0003 
0004    SPDX-License-Identifier: LGPL-3.0-or-later
0005  */
0006 
0007 #ifndef AUDIOWRAPPER_H
0008 #define AUDIOWRAPPER_H
0009 
0010 #include "elisaLib_export.h"
0011 
0012 #include <QObject>
0013 #include <QUrl>
0014 #include <QMediaPlayer>
0015 #include <QString>
0016 
0017 #include <memory>
0018 
0019 class AudioWrapperPrivate;
0020 
0021 class ELISALIB_EXPORT AudioWrapper : public QObject
0022 {
0023     Q_OBJECT
0024 
0025     Q_PROPERTY(bool muted
0026                READ muted
0027                WRITE setMuted
0028                NOTIFY mutedChanged)
0029 
0030     Q_PROPERTY(qreal volume
0031                READ volume
0032                WRITE setVolume
0033                NOTIFY volumeChanged)
0034 
0035     Q_PROPERTY(QUrl source
0036                READ source
0037                WRITE setSource
0038                NOTIFY sourceChanged)
0039 
0040     Q_PROPERTY(QMediaPlayer::MediaStatus status
0041                READ status
0042                NOTIFY statusChanged)
0043 
0044     Q_PROPERTY(QMediaPlayer::PlaybackState playbackState
0045                READ playbackState
0046                NOTIFY playbackStateChanged)
0047 
0048     Q_PROPERTY(QMediaPlayer::Error error
0049                READ error
0050                NOTIFY errorChanged)
0051 
0052     Q_PROPERTY(qint64 duration
0053                READ duration
0054                NOTIFY durationChanged)
0055 
0056     Q_PROPERTY(qint64 position
0057                READ position
0058                WRITE setPosition
0059                NOTIFY positionChanged)
0060 
0061     Q_PROPERTY(bool seekable
0062                READ seekable
0063                NOTIFY seekableChanged)
0064 
0065 public:
0066 
0067     explicit AudioWrapper(QObject *parent = nullptr);
0068 
0069     ~AudioWrapper() override;
0070 
0071     [[nodiscard]] bool muted() const;
0072 
0073     [[nodiscard]] qreal volume() const;
0074 
0075     [[nodiscard]] QUrl source() const;
0076 
0077     [[nodiscard]] QMediaPlayer::MediaStatus status() const;
0078 
0079     [[nodiscard]] QMediaPlayer::PlaybackState playbackState() const;
0080 
0081     [[nodiscard]] QMediaPlayer::Error error() const;
0082 
0083     [[nodiscard]] qint64 duration() const;
0084 
0085     [[nodiscard]] qint64 position() const;
0086 
0087     [[nodiscard]] bool seekable() const;
0088 
0089 Q_SIGNALS:
0090 
0091     void mutedChanged(bool muted);
0092 
0093     void volumeChanged();
0094 
0095     void sourceChanged();
0096 
0097     void statusChanged(QMediaPlayer::MediaStatus status);
0098 
0099     void playbackStateChanged(QMediaPlayer::PlaybackState state);
0100 
0101     void errorChanged(QMediaPlayer::Error error);
0102 
0103     void durationChanged(qint64 duration);
0104 
0105     void positionChanged(qint64 position);
0106 
0107     void currentPlayingForRadiosChanged(const QString &title, const QString &nowPlaying);
0108 
0109     void seekableChanged(bool seekable);
0110 
0111     void playing();
0112 
0113     void paused();
0114 
0115     void stopped();
0116 
0117 public Q_SLOTS:
0118 
0119     void setMuted(bool muted);
0120 
0121     void setVolume(qreal volume);
0122 
0123     void setSource(const QUrl &source);
0124 
0125     void setPosition(qint64 position);
0126 
0127     void saveUndoPosition(qint64 position);
0128 
0129     void restoreUndoPosition();
0130 
0131     void play();
0132 
0133     void pause();
0134 
0135     void stop();
0136 
0137     void seek(qint64 position);
0138 
0139 private Q_SLOTS:
0140 
0141     void mediaStatusChanged();
0142 
0143     void playerStateChanged();
0144 
0145     void playerMutedChanged();
0146 
0147     void playerVolumeChanged();
0148 
0149 private:
0150     void savePosition(qint64 position);
0151 
0152     void playerStateSignalChanges(QMediaPlayer::PlaybackState newState);
0153 
0154     void mediaStatusSignalChanges(QMediaPlayer::MediaStatus newStatus);
0155 
0156     void playerErrorSignalChanges(QMediaPlayer::Error error);
0157 
0158     void playerDurationSignalChanges(qint64 newDuration);
0159 
0160     void playerPositionSignalChanges(qint64 newPosition);
0161 
0162     void playerVolumeSignalChanges();
0163 
0164     void playerMutedSignalChanges(bool isMuted);
0165 
0166     void playerSeekableSignalChanges(bool isSeekable);
0167 
0168     friend class AudioWrapperPrivate;
0169 
0170     std::unique_ptr<AudioWrapperPrivate> d;
0171 
0172 };
0173 
0174 #endif // AUDIOWRAPPER_H