feat: add subtitle track selection, secondary subtitle and delay
This commit is contained in:
1 parent
1eb67b829c
commit
48cac86d60
5 files changed
+320
-4
No files matched your search
@@ -3,6 +3,7 @@
|
||||
#include <MpvAbstractItem>
|
||||
|
||||
#include <QUrl>
|
||||
#include <QVariantList>
|
||||
#include <QtQml/qqmlregistration.h>
|
||||
|
||||
// QML video surface backed by libmpv (through MpvQt).
|
||||
@@ -19,6 +20,14 @@ class MpvItem : public MpvAbstractItem
|
||||
Q_PROPERTY(bool paused READ paused WRITE setPaused NOTIFY pausedChanged)
|
||||
Q_PROPERTY(bool fileLoaded READ isFileLoaded NOTIFY fileLoadedChanged)
|
||||
|
||||
// Subtitle tracks of the current file, each a map with id, title, lang, codec,
|
||||
// external and externalFilename. Track id 0 means "no subtitle".
|
||||
Q_PROPERTY(QVariantList subtitleTracks READ subtitleTracks NOTIFY subtitleTracksChanged)
|
||||
Q_PROPERTY(int subtitleId READ subtitleId WRITE setSubtitleId NOTIFY subtitleTracksChanged)
|
||||
Q_PROPERTY(int secondarySubtitleId READ secondarySubtitleId WRITE setSecondarySubtitleId NOTIFY subtitleTracksChanged)
|
||||
// In seconds; applied to both subtitles so a translation stays in sync with its source.
|
||||
Q_PROPERTY(double subtitleDelay READ subtitleDelay WRITE setSubtitleDelay NOTIFY subtitleDelayChanged)
|
||||
|
||||
public:
|
||||
explicit MpvItem(QQuickItem *parent = nullptr);
|
||||
~MpvItem() override = default;
|
||||
@@ -31,9 +40,21 @@ public:
|
||||
void setPaused(bool paused);
|
||||
bool isFileLoaded() const;
|
||||
|
||||
QVariantList subtitleTracks() const;
|
||||
int subtitleId() const;
|
||||
void setSubtitleId(int id);
|
||||
int secondarySubtitleId() const;
|
||||
void setSecondarySubtitleId(int id);
|
||||
double subtitleDelay() const;
|
||||
void setSubtitleDelay(double seconds);
|
||||
|
||||
Q_INVOKABLE void loadFile(const QUrl &url);
|
||||
Q_INVOKABLE void togglePause();
|
||||
Q_INVOKABLE void seek(double seconds);
|
||||
// Adds an external subtitle file and makes it the primary subtitle.
|
||||
Q_INVOKABLE void addSubtitleFile(const QUrl &url);
|
||||
// Shows a short message on mpv's on-screen display.
|
||||
Q_INVOKABLE void showText(const QString &text);
|
||||
|
||||
Q_SIGNALS:
|
||||
void currentUrlChanged();
|
||||
@@ -42,10 +63,13 @@ Q_SIGNALS:
|
||||
void durationChanged();
|
||||
void pausedChanged();
|
||||
void fileLoadedChanged();
|
||||
void subtitleTracksChanged();
|
||||
void subtitleDelayChanged();
|
||||
|
||||
private:
|
||||
void onPropertyChanged(const QString &property, const QVariant &value);
|
||||
void setFileLoaded(bool loaded);
|
||||
void updateTracks(const QVariantList &trackList);
|
||||
|
||||
bool m_ready = false;
|
||||
QUrl m_pendingUrl;
|
||||
@@ -55,4 +79,8 @@ private:
|
||||
double m_duration = 0.0;
|
||||
bool m_paused = false;
|
||||
bool m_fileLoaded = false;
|
||||
QVariantList m_subtitleTracks;
|
||||
int m_subtitleId = 0;
|
||||
int m_secondarySubtitleId = 0;
|
||||
double m_subtitleDelay = 0.0;
|
||||
};
|
||||
Reference in new issue
Block a user