File indexing completed on 2025-01-19 04:28:11
0001 /** 0002 * SPDX-FileCopyrightText: 2014 Sujith Haridasan <sujith.haridasan@kdemail.net> 0003 * SPDX-FileCopyrightText: 2014 Ashish Madeti <ashishmadeti@gmail.com> 0004 * SPDX-FileCopyrightText: 2016 Matthieu Gallien <matthieu_gallien@yahoo.fr> 0005 * SPDX-FileCopyrightText: 2022-2023 Bart De Vries <bart@mogwai.be> 0006 * 0007 * SPDX-License-Identifier: GPL-3.0-or-later 0008 */ 0009 0010 #pragma once 0011 0012 #include <QDBusAbstractAdaptor> 0013 #include <QDBusMessage> 0014 #include <QDBusObjectPath> 0015 0016 class KMediaSession; 0017 class Entry; 0018 class Feed; 0019 0020 class MediaPlayer2Player : public QDBusAbstractAdaptor 0021 { 0022 Q_OBJECT 0023 Q_CLASSINFO("D-Bus Interface", "org.mpris.MediaPlayer2.Player") // Docs: https://specifications.freedesktop.org/mpris-spec/latest/Player_Interface.html 0024 0025 Q_PROPERTY(QString PlaybackStatus READ PlaybackStatus NOTIFY playbackStatusChanged) 0026 Q_PROPERTY(double Rate READ Rate WRITE setRate NOTIFY rateChanged) 0027 Q_PROPERTY(double MinimumRate READ MinimumRate NOTIFY minimumRateChanged) 0028 Q_PROPERTY(double MaximumRate READ MaximumRate NOTIFY maximumRateChanged) 0029 Q_PROPERTY(QVariantMap Metadata READ Metadata NOTIFY playbackStatusChanged) 0030 Q_PROPERTY(double Volume READ Volume WRITE setVolume NOTIFY volumeChanged) 0031 Q_PROPERTY(qlonglong Position READ Position WRITE setPropertyPosition NOTIFY playbackStatusChanged) 0032 Q_PROPERTY(bool CanGoNext READ CanGoNext NOTIFY canGoNextChanged) 0033 Q_PROPERTY(bool CanGoPrevious READ CanGoPrevious NOTIFY canGoPreviousChanged) 0034 Q_PROPERTY(bool CanPlay READ CanPlay NOTIFY canPlayChanged) 0035 Q_PROPERTY(bool CanPause READ CanPause NOTIFY canPauseChanged) 0036 Q_PROPERTY(bool CanControl READ CanControl NOTIFY canControlChanged) 0037 Q_PROPERTY(bool CanSeek READ CanSeek NOTIFY canSeekChanged) 0038 0039 public: 0040 explicit MediaPlayer2Player(KMediaSession *audioPlayer, bool showProgressOnTaskBar, QObject *parent = nullptr); 0041 0042 QString PlaybackStatus() const; 0043 double Rate() const; 0044 double MinimumRate() const; 0045 double MaximumRate() const; 0046 QVariantMap Metadata() const; 0047 double Volume() const; 0048 qlonglong Position() const; 0049 bool CanGoNext() const; 0050 bool CanGoPrevious() const; 0051 bool CanPlay() const; 0052 bool CanPause() const; 0053 bool CanSeek() const; 0054 bool CanControl() const; 0055 bool showProgressOnTaskBar() const; 0056 void setShowProgressOnTaskBar(bool value); 0057 0058 Q_SIGNALS: 0059 void Seeked(qlonglong Position); 0060 0061 void rateChanged(double newRate); 0062 void minimumRateChanged(double minRate); 0063 void maximumRateChanged(double maxRate); 0064 void volumeChanged(double newVol); 0065 void playbackStatusChanged(); 0066 void canGoNextChanged(); 0067 void canGoPreviousChanged(); 0068 void canPlayChanged(); 0069 void canPauseChanged(); 0070 void canControlChanged(); 0071 void canSeekChanged(); 0072 void next(); 0073 void previous(); 0074 void playPause(); 0075 void stop(); 0076 0077 public Q_SLOTS: 0078 0079 void setRate(double newRate); 0080 void setVolume(double volume); 0081 void Next(); 0082 void Previous(); 0083 void Pause(); 0084 void PlayPause(); 0085 void Stop(); 0086 void Play(); 0087 void Seek(qlonglong Offset); 0088 void SetPosition(const QDBusObjectPath &trackId, qlonglong pos); 0089 void OpenUri(const QString &uri); 0090 0091 private Q_SLOTS: 0092 void playerPlaybackStateChanged(); 0093 void playerPlaybackRateChanged(); 0094 void playerSeeked(qint64 position); 0095 void playerVolumeChanged(); 0096 void playerCanGoNextChanged(); 0097 void playerCanGoPreviousChanged(); 0098 void playerCanPlayChanged(); 0099 void playerCanPauseChanged(); 0100 void playerCanSeekChanged(); 0101 void playerMetaDataChanged(); 0102 0103 // progress on taskbar 0104 void audioPositionChanged(); 0105 void audioDurationChanged(); 0106 0107 private: 0108 void signalPropertiesChange(const QString &property, const QVariant &value); 0109 0110 void setSource(const QUrl &source); 0111 0112 QVariantMap getMetadataOfCurrentTrack(); 0113 0114 KMediaSession *m_audioPlayer = nullptr; 0115 QVariantMap m_metadata; 0116 QString m_currentTrackId; 0117 double m_volume = 0.0; 0118 0119 // progress on taskbar 0120 void setPropertyPosition(int newPositionInMs); 0121 0122 mutable QDBusMessage mProgressIndicatorSignal; 0123 int mPreviousProgressPosition = 0; 0124 bool mShowProgressOnTaskBar = true; 0125 qlonglong m_position = 0; 0126 qlonglong m_lastSentPosition = 0; 0127 };