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

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

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

Loading…
Cancel
Save