File indexing completed on 2024-05-19 04:48:25
0001 /*************************************************************************** 0002 SPDX-FileCopyrightText: 2014 (c) Sujith Haridasan <sujith.haridasan@kdemail.net> 0003 SPDX-FileCopyrightText: 2014 (c) Ashish Madeti <ashishmadeti@gmail.com> 0004 SPDX-FileCopyrightText: 2016 (c) Matthieu Gallien <matthieu_gallien@yahoo.fr> 0005 0006 SPDX-License-Identifier: GPL-3.0-or-later 0007 ***************************************************************************/ 0008 0009 #ifndef MEDIAPLAYER2PLAYER_H 0010 #define MEDIAPLAYER2PLAYER_H 0011 0012 #include <QDBusAbstractAdaptor> 0013 #include <QDBusMessage> 0014 #include <QDBusObjectPath> 0015 0016 class Playlist; 0017 class Player; 0018 0019 class MediaPlayer2Player : public QDBusAbstractAdaptor 0020 { 0021 Q_OBJECT 0022 Q_CLASSINFO("D-Bus Interface", "org.mpris.MediaPlayer2.Player") // Docs: https://specifications.freedesktop.org/mpris-spec/latest/Player_Interface.html 0023 0024 Q_PROPERTY(QString PlaybackStatus READ PlaybackStatus NOTIFY playbackStatusChanged) 0025 Q_PROPERTY(double Rate READ Rate WRITE setRate NOTIFY rateChanged) 0026 Q_PROPERTY(QVariantMap Metadata READ Metadata NOTIFY playbackStatusChanged) 0027 Q_PROPERTY(double Volume READ Volume WRITE setVolume NOTIFY volumeChanged) 0028 Q_PROPERTY(qlonglong Position READ Position WRITE setPropertyPosition NOTIFY playbackStatusChanged) 0029 Q_PROPERTY(double MinimumRate READ MinimumRate CONSTANT) 0030 Q_PROPERTY(double MaximumRate READ MaximumRate CONSTANT) 0031 Q_PROPERTY(bool CanGoNext READ CanGoNext NOTIFY canGoNextChanged) 0032 Q_PROPERTY(bool CanGoPrevious READ CanGoPrevious NOTIFY canGoPreviousChanged) 0033 Q_PROPERTY(bool CanPlay READ CanPlay NOTIFY canPlayChanged) 0034 Q_PROPERTY(bool CanPause READ CanPause NOTIFY canPauseChanged) 0035 Q_PROPERTY(bool CanControl READ CanControl NOTIFY canControlChanged) 0036 Q_PROPERTY(bool CanSeek READ CanSeek NOTIFY canSeekChanged) 0037 Q_PROPERTY(int currentTrack READ currentTrack WRITE setCurrentTrack NOTIFY currentTrackChanged) 0038 Q_PROPERTY(int mediaPlayerPresent READ mediaPlayerPresent WRITE setMediaPlayerPresent NOTIFY mediaPlayerPresentChanged) 0039 0040 public: 0041 explicit MediaPlayer2Player(Playlist *playListControler, Player *audioPlayer, bool showProgressOnTaskBar, QObject *parent = nullptr); 0042 ~MediaPlayer2Player() override; 0043 0044 QString PlaybackStatus() const; 0045 double Rate() const; 0046 QVariantMap Metadata() const; 0047 double Volume() const; 0048 qlonglong Position() const; 0049 double MinimumRate() const; 0050 double MaximumRate() const; 0051 bool CanGoNext() const; 0052 bool CanGoPrevious() const; 0053 bool CanPlay() const; 0054 bool CanPause() const; 0055 bool CanSeek() const; 0056 bool CanControl() const; 0057 int currentTrack() const; 0058 int mediaPlayerPresent() const; 0059 0060 bool showProgressOnTaskBar() const; 0061 void setShowProgressOnTaskBar(bool value); 0062 0063 Q_SIGNALS: 0064 void Seeked(qlonglong Position); 0065 0066 void rateChanged(double newRate); 0067 void volumeChanged(double newVol); 0068 void playbackStatusChanged(); 0069 void canGoNextChanged(); 0070 void canGoPreviousChanged(); 0071 void canPlayChanged(); 0072 void canPauseChanged(); 0073 void canControlChanged(); 0074 void canSeekChanged(); 0075 void currentTrackChanged(); 0076 void mediaPlayerPresentChanged(); 0077 void next(); 0078 void previous(); 0079 void playPause(); 0080 void stop(); 0081 0082 public Q_SLOTS: 0083 0084 void emitSeeked(int pos); 0085 0086 void Next(); 0087 void Previous(); 0088 void Pause(); 0089 void PlayPause(); 0090 void Stop(); 0091 void Play(); 0092 void Seek(qlonglong Offset); 0093 void SetPosition(const QDBusObjectPath &trackId, qlonglong pos); 0094 void OpenUri(const QString &uri); 0095 0096 private Q_SLOTS: 0097 0098 void playerSourceChanged(); 0099 0100 void playControlEnabledChanged(); 0101 0102 void skipBackwardControlEnabledChanged(); 0103 0104 void skipForwardControlEnabledChanged(); 0105 0106 void playerPlaybackStateChanged(); 0107 0108 void playerIsSeekableChanged(); 0109 0110 void audioPositionChanged(); 0111 0112 void audioDurationChanged(); 0113 0114 void playerVolumeChanged(); 0115 0116 private: 0117 void signalPropertiesChange(const QString &property, const QVariant &value); 0118 0119 void setMediaPlayerPresent(int status); 0120 void setRate(double newRate); 0121 void setVolume(double volume); 0122 void setPropertyPosition(int newPositionInMs); 0123 void setCurrentTrack(int newTrackPosition); 0124 0125 QVariantMap getMetadataOfCurrentTrack(); 0126 0127 QVariantMap m_metadata; 0128 QString m_currentTrack; 0129 QString m_currentTrackId; 0130 double m_rate = 1.0; 0131 double m_volume = 0.0; 0132 int m_mediaPlayerPresent = 0; 0133 bool m_canPlay = false; 0134 bool m_canGoNext = false; 0135 bool m_canGoPrevious = false; 0136 qlonglong m_position = 0; 0137 Playlist *m_playListControler = nullptr; 0138 bool m_playerIsSeekableChanged = false; 0139 Player *m_audioPlayer = nullptr; 0140 mutable QDBusMessage mProgressIndicatorSignal; 0141 int mPreviousProgressPosition = 0; 0142 bool mShowProgressOnTaskBar = true; 0143 }; 0144 0145 #endif // MEDIAPLAYER2PLAYER_H