Fix videos being play/paused after a manual stop

When a video is first loaded (placed on the scene), we play/pause it to
load the first frame; but this was also called when the video was
manually stopped. To avoid this, a mStopped attribute was added to
UBGraphicsMediaItem. It is set to true only when the video is stopped by
the user.
preferencesAboutTextFull
Craig Watson 8 years ago
parent d8cba93d59
commit eb597bf26d
  1. 13
      src/domain/UBGraphicsMediaItem.cpp
  2. 2
      src/domain/UBGraphicsMediaItem.h
  3. 3
      src/domain/UBGraphicsMediaItemDelegate.cpp

@ -65,6 +65,7 @@ UBGraphicsMediaItem::UBGraphicsMediaItem(const QUrl& pMediaFileUrl, QGraphicsIte
: QGraphicsRectItem(parent)
, mMuted(sIsMutedByDefault)
, mMutedByUserAction(sIsMutedByDefault)
, mStopped(false)
, mMediaFileUrl(pMediaFileUrl)
, mLinkedImage(NULL)
, mInitialPos(0)
@ -200,6 +201,14 @@ QMediaPlayer::State UBGraphicsMediaItem::playerState() const
return mMediaObject->state();
}
/**
* @brief Returns true if the video was manually stopped, false otherwise.
*/
bool UBGraphicsMediaItem::isStopped() const
{
return mStopped;
}
qint64 UBGraphicsMediaItem::mediaDuration() const
{
return mMediaObject->duration();
@ -320,16 +329,20 @@ void UBGraphicsMediaItem::showOnDisplayChanged(bool shown)
void UBGraphicsMediaItem::play()
{
mMediaObject->play();
mStopped = false;
}
void UBGraphicsMediaItem::pause()
{
mMediaObject->pause();
mStopped = false;
}
void UBGraphicsMediaItem::stop()
{
qDebug() << "stop requested";
mMediaObject->stop();
mStopped = true;
}
void UBGraphicsMediaItem::togglePlayPause()

@ -85,6 +85,7 @@ public:
QMediaPlayer::State playerState() const;
bool isPlaying() const { return (mMediaObject->state() == QMediaPlayer::PlayingState); }
bool isPaused() const { return (mMediaObject->state() == QMediaPlayer::PausedState); }
bool isStopped() const;
QRectF boundingRect() const;
@ -135,6 +136,7 @@ protected:
bool mMuted;
bool mMutedByUserAction;
static bool sIsMutedByDefault;
bool mStopped;
QUrl mMediaFileUrl;
QString mMediaSource;

@ -242,7 +242,8 @@ void UBGraphicsMediaItemDelegate::mediaStatusChanged(QMediaPlayer::MediaStatus s
// At the beginning of the video, play/pause to load and display the first frame
if ((status == QMediaPlayer::LoadedMedia || status == QMediaPlayer::BufferedMedia)
&& delegated()->mediaPosition() == delegated()->initialPos()) {
&& delegated()->mediaPosition() == delegated()->initialPos()
&& !delegated()->isStopped()) {
delegated()->play();
delegated()->pause();
}

Loading…
Cancel
Save