adding a playpause ability in videos

This commit is contained in:
Chris Cochrun 2022-09-15 17:06:04 -05:00
parent 8b7cd23f8b
commit 9a180f7df0
5 changed files with 73 additions and 6 deletions

View file

@ -119,7 +119,7 @@ Item {
visible: itemType === "video"; visible: itemType === "video";
MouseArea { MouseArea {
anchors.fill: parent anchors.fill: parent
onPressed: print("pressed play/plause"); onPressed: SlideObject.playPause();
cursorShape: Qt.PointingHandCursor cursorShape: Qt.PointingHandCursor
} }
} }
@ -149,6 +149,22 @@ Item {
} }
Connections {
target: SlideObject
onVideoBackgroundChanged: {
loadVideo();
}
onIsPlayingChanged: {
if(SlideObject.isPlaying)
previewSlide.playVideo();
pauseVideo();
}
}
function pauseVideo() {
previewSlide.pauseVideo();
}
function loadVideo() { function loadVideo() {
previewSlide.loadVideo(); previewSlide.loadVideo();
} }

View file

@ -14,7 +14,7 @@ Window {
width: maximumWidth width: maximumWidth
screen: presentationScreen screen: presentationScreen
/* flags: Qt.X11BypassWindowManagerHint */ /* flags: Qt.X11BypassWindowManagerHint */
onClosing: presenting = false onClosing: close()
Component.onCompleted: { Component.onCompleted: {
presentationWindow.showFullScreen(); presentationWindow.showFullScreen();
@ -34,6 +34,11 @@ Window {
onVideoBackgroundChanged: { onVideoBackgroundChanged: {
loadVideo(); loadVideo();
} }
onIsPlayingChanged: {
if(SlideObject.isPlaying)
presentationSlide.playVideo();
pauseVideo();
}
} }
function loadVideo() { function loadVideo() {
@ -43,4 +48,14 @@ Window {
function stopVideo() { function stopVideo() {
presentationSlide.stopVideo() presentationSlide.stopVideo()
} }
function pauseVideo() {
presentationSlide.pauseVideo();
}
function close() {
presentationSlide.stopVideo();
SlideObject.pause();
presenting = false;
}
} }

View file

@ -45,7 +45,7 @@ Item {
MpvObject { MpvObject {
id: mpv id: mpv
objectName: "mpv" /* objectName: "mpv" */
anchors.fill: parent anchors.fill: parent
useHwdec: true useHwdec: true
enableAudio: !preview enableAudio: !preview
@ -178,4 +178,8 @@ Item {
function playPauseVideo() { function playPauseVideo() {
mpv.playPause(); mpv.playPause();
} }
function playVideo() {
mpv.play();
}
} }

View file

@ -12,10 +12,12 @@ Slide::Slide(QObject *parent)
Slide::Slide(const QString &text, const QString &audio, const QString &imageBackground, Slide::Slide(const QString &text, const QString &audio, const QString &imageBackground,
const QString &videoBackground, const QString &horizontalTextAlignment, const QString &videoBackground, const QString &horizontalTextAlignment,
const QString &verticalTextAlignment, const QString &font, const QString &verticalTextAlignment, const QString &font,
const int &fontSize, const QString &type, QObject *parent) const int &fontSize, const bool &isPlaying,
const QString &type, QObject *parent)
: QObject(parent),m_text(text),m_audio(audio),m_imageBackground(imageBackground), : QObject(parent),m_text(text),m_audio(audio),m_imageBackground(imageBackground),
m_videoBackground(videoBackground),m_verticalTextAlignment(verticalTextAlignment), m_videoBackground(videoBackground),m_verticalTextAlignment(verticalTextAlignment),
m_horizontalTextAlignment(horizontalTextAlignment),m_font(font),m_fontSize(fontSize),m_type(type) m_horizontalTextAlignment(horizontalTextAlignment),m_font(font),
m_fontSize(fontSize),m_isPlaying(isPlaying),m_type(type)
{ {
qDebug() << "Initializing slide with defaults"; qDebug() << "Initializing slide with defaults";
} }
@ -66,6 +68,11 @@ int Slide::fontSize() const
return m_fontSize; return m_fontSize;
} }
bool Slide::isPlaying() const
{
return m_isPlaying;
}
void Slide::setText(QString text) void Slide::setText(QString text)
{ {
if (m_text == text) if (m_text == text)
@ -231,3 +238,21 @@ bool Slide::previous(QVariantMap prevItem)
return false; return false;
} }
void Slide::play()
{
m_isPlaying = true;
emit isPlayingChanged(m_isPlaying);
}
void Slide::pause()
{
m_isPlaying = false;
emit isPlayingChanged(m_isPlaying);
}
void Slide::playPause()
{
m_isPlaying = !m_isPlaying;
emit isPlayingChanged(m_isPlaying);
}

View file

@ -21,13 +21,14 @@ class Slide : public QObject
WRITE setVerticalTextAlignment NOTIFY verticalTextAlignmentChanged) WRITE setVerticalTextAlignment NOTIFY verticalTextAlignmentChanged)
Q_PROPERTY(QString font READ font WRITE setFont NOTIFY fontChanged) Q_PROPERTY(QString font READ font WRITE setFont NOTIFY fontChanged)
Q_PROPERTY(int fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged) Q_PROPERTY(int fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged)
Q_PROPERTY(bool isPlaying READ isPlaying NOTIFY isPlayingChanged)
// QML_ELEMENT // QML_ELEMENT
public: public:
explicit Slide(QObject *parent = nullptr); explicit Slide(QObject *parent = nullptr);
Slide(const QString &text, const QString &audio, const QString &imageBackground, const QString &videoBackground, Slide(const QString &text, const QString &audio, const QString &imageBackground, const QString &videoBackground,
const QString &horizontalTextAlignment, const QString &verticalTextAlignment, const QString &horizontalTextAlignment, const QString &verticalTextAlignment,
const QString &font, const int &fontSize, const QString &type, QObject * parent = nullptr); const QString &font, const int &fontSize, const bool &isPlaying, const QString &type, QObject * parent = nullptr);
QString text() const; QString text() const;
QString type() const; QString type() const;
@ -39,6 +40,7 @@ public:
QString verticalTextAlignment() const; QString verticalTextAlignment() const;
QString font() const; QString font() const;
int fontSize() const; int fontSize() const;
bool isPlaying() const;
Q_INVOKABLE void setText(QString text); Q_INVOKABLE void setText(QString text);
Q_INVOKABLE void setType(QString type); Q_INVOKABLE void setType(QString type);
@ -52,6 +54,9 @@ public:
Q_INVOKABLE void setFontSize(int fontSize); Q_INVOKABLE void setFontSize(int fontSize);
Q_INVOKABLE void changeSlide(QVariantMap item); Q_INVOKABLE void changeSlide(QVariantMap item);
Q_INVOKABLE void play();
Q_INVOKABLE void pause();
Q_INVOKABLE void playPause();
Q_INVOKABLE bool next(QVariantMap nextItem); Q_INVOKABLE bool next(QVariantMap nextItem);
Q_INVOKABLE bool previous(QVariantMap prevItem); Q_INVOKABLE bool previous(QVariantMap prevItem);
@ -66,6 +71,7 @@ signals:
Q_INVOKABLE void verticalTextAlignmentChanged(QString verticalTextAlignment); Q_INVOKABLE void verticalTextAlignmentChanged(QString verticalTextAlignment);
Q_INVOKABLE void fontChanged(QString font); Q_INVOKABLE void fontChanged(QString font);
Q_INVOKABLE void fontSizeChanged(int fontSize); Q_INVOKABLE void fontSizeChanged(int fontSize);
Q_INVOKABLE void isPlayingChanged(bool isPlaying);
private: private:
int m_id; int m_id;
@ -79,6 +85,7 @@ private:
QString m_verticalTextAlignment; QString m_verticalTextAlignment;
QString m_font; QString m_font;
int m_fontSize; int m_fontSize;
bool m_isPlaying;
int m_slideIndex; int m_slideIndex;
int m_slideSize; int m_slideSize;