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

@ -85,6 +85,7 @@ public:
QMediaPlayer::State playerState() const; QMediaPlayer::State playerState() const;
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;
QRectF boundingRect() const; QRectF boundingRect() const;
@ -135,6 +136,7 @@ protected:
bool mMuted; bool mMuted;
bool mMutedByUserAction; bool mMutedByUserAction;
static bool sIsMutedByDefault; static bool sIsMutedByDefault;
bool mStopped;
QUrl mMediaFileUrl; QUrl mMediaFileUrl;
QString mMediaSource; 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 // At the beginning of the video, play/pause to load and display the first frame
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()->play(); delegated()->play();
delegated()->pause(); delegated()->pause();
} }

Loading…
Cancel
Save