| 1 | // For license of this file, see <project-root-folder>/LICENSE.md. |
| 2 | |
| 3 | #ifndef LIBMPVBACKEND_H |
| 4 | #define LIBMPVBACKEND_H |
| 5 | |
| 6 | #include "gui/mediaplayer/playerbackend.h" |
| 7 | |
| 8 | #include <mpv/client.h> |
| 9 | |
| 10 | class LibMpvWidget; |
| 11 | |
| 12 | class LibMpvBackend : public PlayerBackend { |
| 13 | Q_OBJECT |
| 14 | |
| 15 | public: |
| 16 | explicit LibMpvBackend(Application* app, QWidget* parent = nullptr); |
| 17 | virtual ~LibMpvBackend(); |
| 18 | |
| 19 | public: |
| 20 | virtual bool eventFilter(QObject* watched, QEvent* event); |
| 21 | |
| 22 | virtual QUrl url() const; |
| 23 | virtual int position() const; |
| 24 | virtual int duration() const; |
| 25 | |
| 26 | static void installCustomConfig(const QString& directory); |
| 27 | |
| 28 | public slots: |
| 29 | virtual void setMuted(bool muted); |
| 30 | virtual void playUrl(const QUrl& url); |
| 31 | virtual void playPause(); |
| 32 | virtual void pause(); |
| 33 | virtual void stop(); |
| 34 | virtual void setPlaybackSpeed(int speed); |
| 35 | virtual void setVolume(int volume); |
| 36 | virtual void setPosition(int position); |
| 37 | virtual void setFullscreen(bool fullscreen); |
| 38 | |
| 39 | private slots: |
| 40 | void onMpvEvents(); |
| 41 | |
| 42 | private: |
| 43 | void processEndFile(mpv_event_end_file* end_file); |
| 44 | void processTracks(const QJsonDocument& json); |
| 45 | void processPropertyChange(mpv_event_property* prop, uint64_t property_code); |
| 46 | void processLogMessage(mpv_event_log_message* msg); |
| 47 | void appendLog(const QString& text); |
| 48 | void createPlayer(); |
| 49 | void handleMpvEvent(mpv_event* event); |
| 50 | |
| 51 | const char* mpvDecodeString(void* data) const; |
| 52 | bool mpvDecodeBool(void* data) const; |
| 53 | int mpvDecodeInt(void* data) const; |
| 54 | double mpvDecodeDouble(void* data) const; |
| 55 | QString mpvEncodeKeyboardButton(int btn) const; |
| 56 | QString errorToString(mpv_error error) const; |
| 57 | |
| 58 | void destroyHandle(); |
| 59 | void loadSettings(); |
| 60 | |
| 61 | private: |
| 62 | QString m_customConfigFolder; |
| 63 | LibMpvWidget* m_mpvContainer; |
| 64 | mpv_handle* m_mpvHandle; |
| 65 | QUrl m_url; |
| 66 | }; |
| 67 | |
| 68 | #endif // LIBMPVBACKEND_H |