fixed an issue where the ticker would not update after clicking stop + fixed an issue on linux where play button would have to be clicked several times to replay a video that has been watched entirely (the RessourceError message remains but the user just need to click play once now)

preferencesAboutTextFull
Clément Fauconnier 3 years ago
parent b316108262
commit eedf2867a1
  1. 37
      src/domain/UBGraphicsMediaItem.cpp
  2. 3
      src/domain/UBGraphicsMediaItem.h
  3. 15
      src/domain/UBGraphicsMediaItemDelegate.cpp

@ -68,6 +68,7 @@ UBGraphicsMediaItem::UBGraphicsMediaItem(const QUrl& pMediaFileUrl, QGraphicsIte
, mMuted(sIsMutedByDefault)
, mMutedByUserAction(sIsMutedByDefault)
, mStopped(false)
, mFirstLoad(true)
, mMediaFileUrl(pMediaFileUrl)
, mLinkedImage(NULL)
, mInitialPos(0)
@ -135,8 +136,8 @@ UBGraphicsVideoItem::UBGraphicsVideoItem(const QUrl &pMediaFileUrl, QGraphicsIte
* active scene has changed, or when the item is first created.
* If and when Qt fix this issue, this should be changed back.
* */
//mMediaObject->setVideoOutput(mVideoItem);
mHasVideoOutput = false;
mMediaObject->setVideoOutput(mVideoItem);
mHasVideoOutput = true;
mMediaObject->setNotifyInterval(50);
@ -175,12 +176,12 @@ QVariant UBGraphicsMediaItem::itemChange(GraphicsItemChange change, const QVaria
|| (change == QGraphicsItem::ItemVisibleChange))
{
if (mMediaObject && (!isEnabled() || !isVisible() || !scene()))
mMediaObject->pause();
pause();
}
else if (change == QGraphicsItem::ItemSceneHasChanged)
{
if (!scene())
mMediaObject->stop();
stop();
else {
QString absoluteMediaFilename;
@ -225,6 +226,16 @@ bool UBGraphicsMediaItem::isStopped() const
return mStopped;
}
bool UBGraphicsMediaItem::firstLoad() const
{
return mFirstLoad;
}
void UBGraphicsMediaItem::setFirstLoad(bool firstLoad)
{
mFirstLoad = firstLoad;
}
qint64 UBGraphicsMediaItem::mediaDuration() const
{
return mMediaObject->duration();
@ -333,7 +344,7 @@ UBGraphicsScene* UBGraphicsMediaItem::scene()
void UBGraphicsMediaItem::activeSceneChanged()
{
if (UBApplication::boardController->activeScene() != scene())
mMediaObject->pause();
pause();
}
@ -374,17 +385,19 @@ void UBGraphicsMediaItem::togglePlayPause()
}
if (mMediaObject->state() == QMediaPlayer::StoppedState)
mMediaObject->play();
{
play();
}
else if (mMediaObject->state() == QMediaPlayer::PlayingState) {
if ((mMediaObject->duration() - mMediaObject->position()) <= 0) {
mMediaObject->stop();
mMediaObject->play();
stop();
play();
}
else {
mMediaObject->pause();
pause();
if(scene())
scene()->setModified(true);
}
@ -392,14 +405,14 @@ void UBGraphicsMediaItem::togglePlayPause()
else if (mMediaObject->state() == QMediaPlayer::PausedState) {
if ((mMediaObject->duration() - mMediaObject->position()) <= 0)
mMediaObject->stop();
stop();
mMediaObject->play();
play();
}
else if ( mMediaObject->mediaStatus() == QMediaPlayer::LoadingMedia) {
mMediaObject->setMedia(mediaFileUrl());
mMediaObject->play();
play();
}
}

@ -88,6 +88,8 @@ public:
bool isPlaying() const { return (mMediaObject->state() == QMediaPlayer::PlayingState); }
bool isPaused() const { return (mMediaObject->state() == QMediaPlayer::PausedState); }
bool isStopped() const;
bool firstLoad() const;
void setFirstLoad(bool firstLoad);
QRectF boundingRect() const;
@ -140,6 +142,7 @@ protected:
bool mMutedByUserAction;
static bool sIsMutedByDefault;
bool mStopped;
bool mFirstLoad;
QUrl mMediaFileUrl;
QString mMediaSource;

@ -246,15 +246,22 @@ void UBGraphicsMediaItemDelegate::mediaStatusChanged(QMediaPlayer::MediaStatus s
#ifndef Q_OS_OSX
if ((status == QMediaPlayer::LoadedMedia || status == QMediaPlayer::BufferedMedia)
&& delegated()->mediaPosition() == delegated()->initialPos()
&& !delegated()->isStopped()) {
&& !delegated()->isStopped()
&& delegated()->firstLoad()
)
{
delegated()->play();
delegated()->pause();
delegated()->setFirstLoad(false);
}
#endif
// At the end of the video, make sure the progress bar doesn't autohide
if (status == QMediaPlayer::EndOfMedia)
{
delegated()->setFirstLoad(true);
showToolBar(false);
}
// in most cases, the only necessary action is to update the play/pause state
@ -267,6 +274,9 @@ void UBGraphicsMediaItemDelegate::mediaStateChanged(QMediaPlayer::State state)
// Possible states are StoppedState, PlayingState and PausedState
// updatePlayPauseState handles this functionality
if (state == QMediaPlayer::StoppedState)
delegated()->setMediaPos(0);
updatePlayPauseState();
}
@ -282,8 +292,11 @@ void UBGraphicsMediaItemDelegate::updatePlayPauseState()
void UBGraphicsMediaItemDelegate::updateTicker(qint64 time)
{
if (!delegated()->isStopped())
{
mMediaControl->totalTimeChanged(delegated()->mediaDuration());
mMediaControl->updateTicker(time);
}
}

Loading…
Cancel
Save