From d99e56af7aa547b4889d89ad2dcdc0a07c0d5314 Mon Sep 17 00:00:00 2001 From: Mikhail Lobotskiy Date: Fri, 14 Jun 2024 15:07:25 +0400 Subject: [PATCH 1/2] Add player commands and improved `stop` command --- .../lib/qt_wrapper/src/qcefview_media.cpp | 19 +++++++++++++++++- .../videoplayerlib/qascvideoview.h | 4 +++- .../videoplayerlib/src/qascvideoview.cpp | 20 ++++++++++++++----- .../videoplayerlib/src/qascvideowidget.cpp | 9 ++++++++- .../videoplayerlib/src/qascvideowidget.h | 3 +-- .../videoplayerlib/src/qfooterpanel.cpp | 2 +- 6 files changed, 46 insertions(+), 11 deletions(-) diff --git a/ChromiumBasedEditors/lib/qt_wrapper/src/qcefview_media.cpp b/ChromiumBasedEditors/lib/qt_wrapper/src/qcefview_media.cpp index f6c00021..db6ddd88 100644 --- a/ChromiumBasedEditors/lib/qt_wrapper/src/qcefview_media.cpp +++ b/ChromiumBasedEditors/lib/qt_wrapper/src/qcefview_media.cpp @@ -108,7 +108,7 @@ void QCefView_Media::OnMediaEnd(bool isFromResize) void QCefView_Media::OnMediaPlayerCommand(NSEditorApi::CAscExternalMediaPlayerCommand* data) { std::string sCmd = data->get_Cmd(); - + // panel and video widget commands if (sCmd == "showMediaControl") { showMediaControl(data); @@ -121,6 +121,23 @@ void QCefView_Media::OnMediaPlayerCommand(NSEditorApi::CAscExternalMediaPlayerCo { updateGeometry(data); } + // player commands + else if (sCmd == "play" || sCmd == "resume") + { + m_pMediaView->Play(); + } + else if (sCmd == "pause") + { + m_pMediaView->Pause(); + } + else if (sCmd == "stop") + { + m_pMediaView->Stop(); + } + else if (sCmd == "togglePause") + { + m_pMediaView->TogglePause(); + } else { #ifdef DEBUG_MEDIA_PLAYER diff --git a/ChromiumBasedEditors/videoplayerlib/qascvideoview.h b/ChromiumBasedEditors/videoplayerlib/qascvideoview.h index feeffb5e..ae812274 100644 --- a/ChromiumBasedEditors/videoplayerlib/qascvideoview.h +++ b/ChromiumBasedEditors/videoplayerlib/qascvideoview.h @@ -51,7 +51,9 @@ public: virtual QWidget* getMainWindow(); public: - void PlayPause(); + void Play(); + void Pause(); + void TogglePause(); void ChangeVolume(int nValue); void ChangeSeek(int nValue); void ToggleMute(); diff --git a/ChromiumBasedEditors/videoplayerlib/src/qascvideoview.cpp b/ChromiumBasedEditors/videoplayerlib/src/qascvideoview.cpp index 34eee1e6..e7c4f37c 100644 --- a/ChromiumBasedEditors/videoplayerlib/src/qascvideoview.cpp +++ b/ChromiumBasedEditors/videoplayerlib/src/qascvideoview.cpp @@ -114,7 +114,6 @@ QAscVideoView::QAscVideoView(QWidget *parent, bool bIsPresentationMode) : QWidge m_pInternal->m_bIsEnabledPlayList = true; m_pInternal->m_bIsEnabledFullscreen = true; m_pInternal->m_bIsPresentationModeMediaTypeSended = false; - m_pInternal->m_bIsDestroy = false; m_pInternal->m_bIsMuted = false; m_pInternal->m_bIsSeekEnabled = true; @@ -271,7 +270,7 @@ void QAscVideoView::keyPressEvent(QKeyEvent *event) } case Qt::Key_Space: { - PlayPause(); + TogglePause(); break; } case Qt::Key_M: @@ -318,7 +317,17 @@ bool QAscVideoView::eventFilter(QObject *watched, QEvent *event) return QWidget::eventFilter(watched, event); } -void QAscVideoView::PlayPause() +void QAscVideoView::Play() +{ + m_pInternal->m_pPlayer->setPlay(); +} + +void QAscVideoView::Pause() +{ + m_pInternal->m_pPlayer->setPause(); +} + +void QAscVideoView::TogglePause() { if (m_pInternal->m_bIsPlay) m_pInternal->m_pPlayer->setPlay(); @@ -458,8 +467,9 @@ void QAscVideoView::setMedia(QString sMedia, bool isStart) void QAscVideoView::Stop() { - m_pInternal->m_bIsDestroy = true; m_pInternal->m_pPlayer->stop(); + this->hide(); + m_pInternal->m_bIsPresentationModeMediaTypeSended = false; } void QAscVideoView::RemoveFromPresentation() @@ -558,7 +568,7 @@ void QAscVideoView::slotVideoAvailableChanged(bool isVideoAvailable) if (m_pInternal->m_bIsPresentationMode && !m_pInternal->m_bIsPresentationModeMediaTypeSended) { m_pInternal->m_bIsPresentationModeMediaTypeSended = true; - if (!m_pInternal->m_pPlayer->isAudio() && !m_pInternal->m_bIsDestroy) + if (!m_pInternal->m_pPlayer->isAudio()) { this->show(); Footer()->show(); diff --git a/ChromiumBasedEditors/videoplayerlib/src/qascvideowidget.cpp b/ChromiumBasedEditors/videoplayerlib/src/qascvideowidget.cpp index 4be4997a..2b6b6e79 100644 --- a/ChromiumBasedEditors/videoplayerlib/src/qascvideowidget.cpp +++ b/ChromiumBasedEditors/videoplayerlib/src/qascvideowidget.cpp @@ -81,6 +81,7 @@ QAscVideoWidget::QAscVideoWidget(QWidget *parent) QObject::connect(m_pEngine, SIGNAL(positionChanged(qint64)), this, SLOT(slotPositionChange(qint64))); QObject::connect(m_pEngine, SIGNAL(videoAvailableChanged(bool)), this, SLOT(slotVideoAvailableChanged(bool))); QObject::connect(m_pEngine, SIGNAL(durationChanged(qint64)), this, SLOT(slotMediaDurationParsed(qint64))); + QObject::connect(m_pEngine, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)), this, SLOT(slotMediaStatusChanged(QMediaPlayer::MediaStatus))); #else m_pVlcPlayer = new CVlcPlayer(this); m_pVlcPlayer->integrateIntoWidget(this); @@ -438,7 +439,7 @@ void QAscVideoWidget::slotVlcStateChanged(int state) } } } - else if (state == libvlc_Ended) + else if (state == libvlc_Ended || state == libvlc_Stopped) { stateQ = QMediaPlayer::StoppedState; m_sCurrentSource = ""; @@ -512,6 +513,12 @@ void QAscVideoWidget::slotMediaDurationParsed(qint64 duration) } } +void QAscVideoWidget::slotMediaStatusChanged(QMediaPlayer::MediaStatus mediaStatus) +{ + if (mediaStatus == QMediaPlayer::LoadedMedia) + emit videoOutputChanged(m_pEngine->isVideoAvailable()); +} + QMediaPlayer* QAscVideoWidget::getEngine() { return m_pEngine; diff --git a/ChromiumBasedEditors/videoplayerlib/src/qascvideowidget.h b/ChromiumBasedEditors/videoplayerlib/src/qascvideowidget.h index 37fe1abe..b7df54e8 100644 --- a/ChromiumBasedEditors/videoplayerlib/src/qascvideowidget.h +++ b/ChromiumBasedEditors/videoplayerlib/src/qascvideowidget.h @@ -41,8 +41,6 @@ public: bool m_bIsPresentationMode; bool m_bIsPresentationModeMediaTypeSended; - bool m_bIsDestroy; - bool m_bIsMuted; int m_nMutedVolume; @@ -106,6 +104,7 @@ public slots: void slotPositionChange(qint64 pos); void slotVideoAvailableChanged(bool isAvailable); void slotMediaDurationParsed(qint64 duration); + void slotMediaStatusChanged(QMediaPlayer::MediaStatus mediaStatus); #endif public: diff --git a/ChromiumBasedEditors/videoplayerlib/src/qfooterpanel.cpp b/ChromiumBasedEditors/videoplayerlib/src/qfooterpanel.cpp index 4fb7862b..80cb1374 100644 --- a/ChromiumBasedEditors/videoplayerlib/src/qfooterpanel.cpp +++ b/ChromiumBasedEditors/videoplayerlib/src/qfooterpanel.cpp @@ -258,7 +258,7 @@ void QFooterPanel::setTimeOnLabel(qint64 time) void QFooterPanel::onPlayPauseBtnClicked() { - m_pInternal->m_pView->PlayPause(); + m_pInternal->m_pView->TogglePause(); } void QFooterPanel::onVolumeBtnClicked() From 685896c13697f71e3813c7ec97ac588da2e6d379 Mon Sep 17 00:00:00 2001 From: Mikhail Lobotskiy Date: Tue, 18 Jun 2024 16:17:38 +0400 Subject: [PATCH 2/2] Fix bug 68206 --- .../lib/qt_wrapper/src/qcefview_media.cpp | 23 +++++------ .../videoplayerlib/qascvideoview.h | 4 +- .../videoplayerlib/src/qascvideoview.cpp | 38 ++++++++++++++++--- .../videoplayerlib/src/qascvideowidget.cpp | 9 ++++- .../videoplayerlib/src/qascvideowidget.h | 3 +- .../videoplayerlib/src/qfooterpanel.cpp | 2 +- 6 files changed, 55 insertions(+), 24 deletions(-) diff --git a/ChromiumBasedEditors/lib/qt_wrapper/src/qcefview_media.cpp b/ChromiumBasedEditors/lib/qt_wrapper/src/qcefview_media.cpp index 06b3e82d..978bf737 100644 --- a/ChromiumBasedEditors/lib/qt_wrapper/src/qcefview_media.cpp +++ b/ChromiumBasedEditors/lib/qt_wrapper/src/qcefview_media.cpp @@ -251,8 +251,9 @@ void QCefView_Media::showMediaControl(NSEditorApi::CAscExternalMediaPlayerComman int xOffset = 0, yOffset = 0; m_pMediaView = new QAscVideoView(getMainPanel(this, xOffset, yOffset), true); - QObject::connect(m_pMediaView, SIGNAL(onKeyDown(int, Qt::KeyboardModifiers)), - this, SLOT(onMediaKeyDown(int, Qt::KeyboardModifiers))); + // NOTE: uncomment if you want to handle key events from media player + // QObject::connect(m_pMediaView, SIGNAL(onKeyDown(int,Qt::KeyboardModifiers)), + // this, SLOT(onMediaKeyDown(int,Qt::KeyboardModifiers))); m_pMediaView->setPlayListUsed(false); m_pMediaView->setFullScreenUsed(false); @@ -289,7 +290,6 @@ void QCefView_Media::hideMediaControl() if (!m_pMediaView) return; - m_pMediaView->disconnect(); m_pMediaView->RemoveFromPresentation(); m_pMediaView = nullptr; } @@ -308,15 +308,10 @@ void QCefView_Media::updateGeometry(NSEditorApi::CAscExternalMediaPlayerCommand* void QCefView_Media::onMediaKeyDown(int key, Qt::KeyboardModifiers mods) { - switch (key) - { - case Qt::Key_Escape: - { - hideMediaControl(); - setFocus(); - break; - } - default: - break; - } + // NOTE: here can be handled some key events while media is playing + // switch (key) + // { + // default: + // break; + // } } diff --git a/ChromiumBasedEditors/videoplayerlib/qascvideoview.h b/ChromiumBasedEditors/videoplayerlib/qascvideoview.h index d35fccb8..62dcce45 100644 --- a/ChromiumBasedEditors/videoplayerlib/qascvideoview.h +++ b/ChromiumBasedEditors/videoplayerlib/qascvideoview.h @@ -51,7 +51,9 @@ public: virtual QWidget* getMainWindow(); public: - void PlayPause(); + void Play(); + void Pause(); + void TogglePause(); void ChangeVolume(int nValue); void ChangeSeek(int nValue); void ToggleMute(); diff --git a/ChromiumBasedEditors/videoplayerlib/src/qascvideoview.cpp b/ChromiumBasedEditors/videoplayerlib/src/qascvideoview.cpp index eb42aad6..7a04c041 100644 --- a/ChromiumBasedEditors/videoplayerlib/src/qascvideoview.cpp +++ b/ChromiumBasedEditors/videoplayerlib/src/qascvideoview.cpp @@ -117,7 +117,6 @@ QAscVideoView::QAscVideoView(QWidget *parent, bool bIsPresentationMode) : QWidge m_pInternal->m_bIsEnabledPlayList = true; m_pInternal->m_bIsEnabledFullscreen = true; m_pInternal->m_bIsPresentationModeMediaTypeSended = false; - m_pInternal->m_bIsDestroy = false; m_pInternal->m_bIsMuted = false; m_pInternal->m_bIsSeekEnabled = true; @@ -268,13 +267,16 @@ void QAscVideoView::keyPressEvent(QKeyEvent *event) } case Qt::Key_O: { + if (m_pInternal->m_bIsPresentationMode) + break; + if (static_cast(ee) == Qt::ControlModifier) m_pInternal->m_pPlaylist->slotButtonAdd(); break; } case Qt::Key_Space: { - PlayPause(); + TogglePause(); break; } case Qt::Key_M: @@ -284,15 +286,30 @@ void QAscVideoView::keyPressEvent(QKeyEvent *event) } case Qt::Key_N: { + if (m_pInternal->m_bIsPresentationMode) + break; + Footer()->m_pInternal->m_pSlider->setValue(100000); m_pInternal->m_pPlaylist->Next(); break; } case Qt::Key_P: { + if (m_pInternal->m_bIsPresentationMode) + break; + Footer()->m_pInternal->m_pSlider->setValue(0); m_pInternal->m_pPlaylist->Prev(); } + case Qt::Key_Escape: + { + if (m_pInternal->m_bIsPresentationMode) + { + Stop(); + parentWidget()->setFocus(); + } + break; + } default: break; } @@ -323,7 +340,17 @@ bool QAscVideoView::eventFilter(QObject *watched, QEvent *event) return QWidget::eventFilter(watched, event); } -void QAscVideoView::PlayPause() +void QAscVideoView::Play() +{ + m_pInternal->m_pPlayer->setPlay(); +} + +void QAscVideoView::Pause() +{ + m_pInternal->m_pPlayer->setPause(); +} + +void QAscVideoView::TogglePause() { if (m_pInternal->m_bIsPlay) m_pInternal->m_pPlayer->setPlay(); @@ -463,8 +490,9 @@ void QAscVideoView::setMedia(QString sMedia, bool isStart) void QAscVideoView::Stop() { - m_pInternal->m_bIsDestroy = true; m_pInternal->m_pPlayer->stop(); + this->hide(); + m_pInternal->m_bIsPresentationModeMediaTypeSended = false; } void QAscVideoView::RemoveFromPresentation() @@ -563,7 +591,7 @@ void QAscVideoView::slotVideoAvailableChanged(bool isVideoAvailable) if (m_pInternal->m_bIsPresentationMode && !m_pInternal->m_bIsPresentationModeMediaTypeSended) { m_pInternal->m_bIsPresentationModeMediaTypeSended = true; - if (!m_pInternal->m_pPlayer->isAudio() && !m_pInternal->m_bIsDestroy) + if (!m_pInternal->m_pPlayer->isAudio()) { this->show(); Footer()->show(); diff --git a/ChromiumBasedEditors/videoplayerlib/src/qascvideowidget.cpp b/ChromiumBasedEditors/videoplayerlib/src/qascvideowidget.cpp index 94aa3f51..178a1b82 100644 --- a/ChromiumBasedEditors/videoplayerlib/src/qascvideowidget.cpp +++ b/ChromiumBasedEditors/videoplayerlib/src/qascvideowidget.cpp @@ -91,6 +91,7 @@ QAscVideoWidget::QAscVideoWidget(QWidget *parent) QObject::connect(m_pEngine, SIGNAL(positionChanged(qint64)), this, SLOT(slotPositionChange(qint64))); QObject::connect(m_pEngine, SIGNAL(videoAvailableChanged(bool)), this, SLOT(slotVideoAvailableChanged(bool))); QObject::connect(m_pEngine, SIGNAL(durationChanged(qint64)), this, SLOT(slotMediaDurationParsed(qint64))); + QObject::connect(m_pEngine, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)), this, SLOT(slotMediaStatusChanged(QMediaPlayer::MediaStatus))); #else m_pVlcPlayer = new CVlcPlayer(this); m_pVlcPlayer->integrateIntoWidget(this); @@ -459,7 +460,7 @@ void QAscVideoWidget::slotVlcStateChanged(int state) } } } - else if (state == libvlc_Ended) + else if (state == libvlc_Ended || state == libvlc_Stopped) { stateQ = QMediaPlayer::StoppedState; m_sCurrentSource = ""; @@ -533,6 +534,12 @@ void QAscVideoWidget::slotMediaDurationParsed(qint64 duration) } } +void QAscVideoWidget::slotMediaStatusChanged(QMediaPlayer::MediaStatus mediaStatus) +{ + if (mediaStatus == QMediaPlayer::LoadedMedia) + emit videoOutputChanged(m_pEngine->isVideoAvailable()); +} + QMediaPlayer* QAscVideoWidget::getEngine() { return m_pEngine; diff --git a/ChromiumBasedEditors/videoplayerlib/src/qascvideowidget.h b/ChromiumBasedEditors/videoplayerlib/src/qascvideowidget.h index abbb358e..44e555d4 100644 --- a/ChromiumBasedEditors/videoplayerlib/src/qascvideowidget.h +++ b/ChromiumBasedEditors/videoplayerlib/src/qascvideowidget.h @@ -49,8 +49,6 @@ public: bool m_bIsPresentationMode; bool m_bIsPresentationModeMediaTypeSended; - bool m_bIsDestroy; - bool m_bIsMuted; int m_nMutedVolume; @@ -118,6 +116,7 @@ public slots: void slotPositionChange(qint64 pos); void slotVideoAvailableChanged(bool isAvailable); void slotMediaDurationParsed(qint64 duration); + void slotMediaStatusChanged(QMediaPlayer::MediaStatus mediaStatus); #endif public: diff --git a/ChromiumBasedEditors/videoplayerlib/src/qfooterpanel.cpp b/ChromiumBasedEditors/videoplayerlib/src/qfooterpanel.cpp index 4b97e719..01fadbaf 100644 --- a/ChromiumBasedEditors/videoplayerlib/src/qfooterpanel.cpp +++ b/ChromiumBasedEditors/videoplayerlib/src/qfooterpanel.cpp @@ -258,7 +258,7 @@ void QFooterPanel::setTimeOnLabel(qint64 time) void QFooterPanel::onPlayPauseBtnClicked() { - m_pInternal->m_pView->PlayPause(); + m_pInternal->m_pView->TogglePause(); } void QFooterPanel::onVolumeBtnClicked()