Commit eb597bf2 authored by Craig Watson's avatar Craig Watson

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.
parent d8cba93d
...@@ -65,6 +65,7 @@ UBGraphicsMediaItem::UBGraphicsMediaItem(const QUrl& pMediaFileUrl, QGraphicsIte ...@@ -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 ...@@ -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) ...@@ -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: ...@@ -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: ...@@ -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 ...@@ -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();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment