File indexing completed on 2024-12-08 07:36:11

0001 // SPDX-FileCopyrightText: 2019 Linus Jahn <lnj@kaidan.im>
0002 // SPDX-FileCopyrightText: 2022 Devin Lin <devin@kde.org>
0003 // SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
0004 //
0005 // SPDX-License-Identifier: GPL-3.0-or-later
0006 
0007 #pragma once
0008 
0009 #include <MpvAbstractItem>
0010 
0011 class MpvPlayer : public MpvAbstractItem
0012 {
0013     Q_OBJECT
0014     QML_ELEMENT
0015 
0016     Q_PROPERTY(QString source READ source WRITE setSource NOTIFY sourceChanged)
0017     Q_PROPERTY(qreal position READ position NOTIFY positionChanged)
0018     Q_PROPERTY(qreal duration READ duration NOTIFY durationChanged)
0019     Q_PROPERTY(bool paused READ paused NOTIFY pausedChanged)
0020     Q_PROPERTY(QSize sourceSize READ sourceSize NOTIFY sourceSizeChanged)
0021     Q_PROPERTY(bool loading READ loading NOTIFY loadingChanged)
0022     Q_PROPERTY(bool looping READ looping WRITE setLooping NOTIFY loopingChanged)
0023     Q_PROPERTY(bool autoPlay READ autoPlay WRITE setAutoPlay NOTIFY autoPlayChanged)
0024     Q_PROPERTY(bool stopped READ stopped NOTIFY stoppedChanged)
0025 
0026 public:
0027     explicit MpvPlayer(QQuickItem *parent = nullptr);
0028     ~MpvPlayer() = default;
0029 
0030     qreal position() const;
0031     qreal duration() const;
0032     bool paused() const;
0033     QSize sourceSize() const;
0034     QString source() const;
0035     bool loading() const;
0036     bool looping() const;
0037     bool autoPlay() const;
0038     bool stopped() const;
0039 
0040     void setSource(const QString &source);
0041     void setLooping(bool loop);
0042     void setAutoPlay(bool autoPlay);
0043 
0044 public Q_SLOTS:
0045     Q_INVOKABLE void play();
0046     Q_INVOKABLE void pause();
0047     Q_INVOKABLE void stop();
0048     Q_INVOKABLE void setPosition(double value);
0049     void seek(qreal offset);
0050 
0051 Q_SIGNALS:
0052     void positionChanged();
0053     void durationChanged();
0054     void pausedChanged();
0055     void onUpdate();
0056     void sourceSizeChanged();
0057     void sourceChanged();
0058     void loadingChanged();
0059     void loopingChanged();
0060     void autoPlayChanged();
0061     void stoppedChanged();
0062 
0063 private:
0064     void onPropertyChanged(const QString &property, const QVariant &value);
0065 
0066     bool m_paused = true;
0067     qreal m_position = 0;
0068     qreal m_duration = 0;
0069     QSize m_sourceSize;
0070     QString m_source;
0071     QString m_currentSource;
0072     bool m_loading = false;
0073     bool m_looping = false;
0074     bool m_autoPlay = false;
0075 };