diff options
author | Justin McPherson <justin.mcpherson@nokia.com> | 2010-03-19 02:56:15 (GMT) |
---|---|---|
committer | Justin McPherson <justin.mcpherson@nokia.com> | 2010-03-19 05:31:59 (GMT) |
commit | 0d4572595698502e04f491bfea3e16bb1851b645 (patch) | |
tree | 3e5545fdf75012a6f899bf4839f4b1556ab9e7e2 /src/imports | |
parent | abf09f87af8f57f670904ff25a626d19ec11120b (diff) | |
download | Qt-0d4572595698502e04f491bfea3e16bb1851b645.zip Qt-0d4572595698502e04f491bfea3e16bb1851b645.tar.gz Qt-0d4572595698502e04f491bfea3e16bb1851b645.tar.bz2 |
Fix; QML Video item is sensitive to property assignment order
Task-number: QTBUG-8605
Reviewed-by: Andrew den Exter
Diffstat (limited to 'src/imports')
-rw-r--r-- | src/imports/multimedia/qdeclarativeaudio.cpp | 36 | ||||
-rw-r--r-- | src/imports/multimedia/qdeclarativeaudio_p.h | 2 | ||||
-rw-r--r-- | src/imports/multimedia/qdeclarativemediabase.cpp | 219 | ||||
-rw-r--r-- | src/imports/multimedia/qdeclarativemediabase_p.h | 11 | ||||
-rw-r--r-- | src/imports/multimedia/qdeclarativevideo.cpp | 56 | ||||
-rw-r--r-- | src/imports/multimedia/qdeclarativevideo_p.h | 2 |
6 files changed, 212 insertions, 114 deletions
diff --git a/src/imports/multimedia/qdeclarativeaudio.cpp b/src/imports/multimedia/qdeclarativeaudio.cpp index 40133ee..39223dc 100644 --- a/src/imports/multimedia/qdeclarativeaudio.cpp +++ b/src/imports/multimedia/qdeclarativeaudio.cpp @@ -77,7 +77,6 @@ void QDeclarativeAudio::_q_error(int errorCode, const QString &errorString) QDeclarativeAudio::QDeclarativeAudio(QObject *parent) : QObject(parent) { - setObject(this); } QDeclarativeAudio::~QDeclarativeAudio() @@ -94,13 +93,12 @@ QDeclarativeAudio::~QDeclarativeAudio() */ void QDeclarativeAudio::play() -{ - m_playerControl->play(); +{ + if (m_playerControl == 0) + return; - if (m_paused) { - m_paused = false; - emit pausedChanged(); - } + setPaused(false); + setPlaying(true); } /*! @@ -113,12 +111,11 @@ void QDeclarativeAudio::play() void QDeclarativeAudio::pause() { - m_playerControl->pause(); + if (m_playerControl == 0) + return; - if (!m_paused && m_state == QMediaPlayer::PausedState) { - m_paused = true; - emit pausedChanged(); - } + setPaused(true); + setPlaying(true); } /*! @@ -131,12 +128,11 @@ void QDeclarativeAudio::pause() void QDeclarativeAudio::stop() { - m_playerControl->stop(); + if (m_playerControl == 0) + return; - if (m_paused) { - m_paused = false; - emit pausedChanged(); - } + setPlaying(false); + setPaused(false); } /*! @@ -307,6 +303,12 @@ QDeclarativeAudio::Error QDeclarativeAudio::error() const return Error(m_error); } +void QDeclarativeAudio::componentComplete() +{ + setObject(this); +} + + /*! \qmlproperty string Audio::errorString diff --git a/src/imports/multimedia/qdeclarativeaudio_p.h b/src/imports/multimedia/qdeclarativeaudio_p.h index 9881dbc..2e8ae30 100644 --- a/src/imports/multimedia/qdeclarativeaudio_p.h +++ b/src/imports/multimedia/qdeclarativeaudio_p.h @@ -114,6 +114,8 @@ public: Status status() const; Error error() const; + void componentComplete(); + public Q_SLOTS: void play(); void pause(); diff --git a/src/imports/multimedia/qdeclarativemediabase.cpp b/src/imports/multimedia/qdeclarativemediabase.cpp index 8e87e44..542c931 100644 --- a/src/imports/multimedia/qdeclarativemediabase.cpp +++ b/src/imports/multimedia/qdeclarativemediabase.cpp @@ -131,43 +131,56 @@ private: void QDeclarativeMediaBase::_q_stateChanged(QMediaPlayer::State state) { - if (state != m_state) { - QMediaPlayer::State oldState = m_state; + if (m_state == state) + return; - m_state = state; - - if (state == QMediaPlayer::StoppedState) { + switch (state) { + case QMediaPlayer::StoppedState: { emit stopped(); - emit playingChanged(); - } else if (oldState == QMediaPlayer::StoppedState) { - emit started(); - emit playingChanged(); - } else if (oldState == QMediaPlayer::PausedState) { - m_paused = false; - - emit resumed(); - emit pausedChanged(); - } - - if (state == m_state && state == QMediaPlayer::PausedState) { - bool wasPaused = m_paused; - - m_paused = true; + if (m_playing) { + m_playing = false; + emit playingChanged(); + } + } + break; + case QMediaPlayer::PausedState: { emit paused(); - if (!wasPaused) + if (!m_paused) { + m_paused = true; emit pausedChanged(); - } + } - if (m_state == QMediaPlayer::PlayingState - || m_status == QMediaPlayer::BufferingMedia - || m_status == QMediaPlayer::StalledMedia) { - m_animation->start(); - } else { - m_animation->stop(); + if (m_state == QMediaPlayer::StoppedState) + emit started(); } + break; + case QMediaPlayer::PlayingState: { + if (m_state == QMediaPlayer::PausedState) + emit resumed(); + else + emit started(); + + if (m_paused) { + m_paused = false; + emit pausedChanged(); + } + } + break; + } + + // Check + if (state == QMediaPlayer::PlayingState + || m_status == QMediaPlayer::BufferingMedia + || m_status == QMediaPlayer::StalledMedia) { + m_animation->start(); } + else { + m_animation->stop(); + } + + m_state = state; } void QDeclarativeMediaBase::_q_mediaStatusChanged(QMediaPlayer::MediaStatus status) @@ -213,7 +226,13 @@ void QDeclarativeMediaBase::_q_metaDataChanged() } QDeclarativeMediaBase::QDeclarativeMediaBase() - : m_mediaService(0) + : m_paused(false) + , m_playing(false) + , m_muted(false) + , m_position(0) + , m_volume(1.0) + , m_playbackRate(1.0) + , m_mediaService(0) , m_playerControl(0) , m_mediaObject(0) , m_mediaProvider(0) @@ -222,8 +241,7 @@ QDeclarativeMediaBase::QDeclarativeMediaBase() , m_animation(0) , m_state(QMediaPlayer::StoppedState) , m_status(QMediaPlayer::NoMedia) - , m_error(QMediaPlayer::NoError) - , m_paused(false) + , m_error(QMediaPlayer::ServiceMissingError) { } @@ -280,9 +298,8 @@ void QDeclarativeMediaBase::setObject(QObject *object) object, SLOT(_q_error(int,QString))); m_animation = new QDeclarativeMediaBaseAnimation(this); + m_error = QMediaPlayer::NoError; } else { - m_error = QMediaPlayer::ServiceMissingError; - m_playerControl = new QDeclarativeMediaBasePlayerControl(object); } @@ -292,40 +309,74 @@ void QDeclarativeMediaBase::setObject(QObject *object) QObject::connect(m_metaDataControl, SIGNAL(metaDataChanged()), object, SLOT(_q_metaDataChanged())); } + + // Init + m_playerControl->setVolume(m_volume * 100); + m_playerControl->setMuted(m_muted); + m_playerControl->setPlaybackRate(m_playbackRate); + + if (!m_source.isEmpty()) + m_playerControl->setMedia(m_source, 0); + + if (m_playing) + m_playerControl->play(); + + if (m_position > 0) + m_playerControl->setPosition(m_position); } + +// Properties + QUrl QDeclarativeMediaBase::source() const { - return m_playerControl->media().canonicalUrl(); + return m_source; } void QDeclarativeMediaBase::setSource(const QUrl &url) { - if (m_error != QMediaPlayer::ServiceMissingError && m_error != QMediaPlayer::NoError) { - m_error = QMediaPlayer::NoError; - m_errorString = QString(); + if (url == m_source) + return; - emit errorChanged(); - } + m_source = url; + + if (m_playerControl != 0) { + if (m_error != QMediaPlayer::ServiceMissingError && m_error != QMediaPlayer::NoError) { + m_error = QMediaPlayer::NoError; + m_errorString = QString(); + + emit errorChanged(); + } - m_playerControl->setMedia(QMediaContent(url), 0); + m_playerControl->setMedia(m_source, 0); + } + else + emit sourceChanged(); } bool QDeclarativeMediaBase::isPlaying() const { - return m_state != QMediaPlayer::StoppedState; + return m_playing; } void QDeclarativeMediaBase::setPlaying(bool playing) { - if (playing && m_state == QMediaPlayer::StoppedState) { - if (m_paused) - m_playerControl->pause(); - else - m_playerControl->play(); - } else if (!playing) { - m_playerControl->stop(); + if (playing == m_playing) + return; + + m_playing = playing; + if (m_playerControl != 0) { + if (m_playing) { + if (!m_paused) + m_playerControl->play(); + else + m_playerControl->pause(); + } + else if (m_state != QMediaPlayer::StoppedState) + m_playerControl->stop(); } + + emit playingChanged(); } bool QDeclarativeMediaBase::isPaused() const @@ -335,73 +386,107 @@ bool QDeclarativeMediaBase::isPaused() const void QDeclarativeMediaBase::setPaused(bool paused) { - if (m_paused != paused) { - if (paused && m_state == QMediaPlayer::PlayingState) { + if (m_paused == paused) + return; + + m_paused = paused; + if (m_playerControl != 0) { + // Check if completed, change state + if (m_paused && m_state == QMediaPlayer::PlayingState) { m_playerControl->pause(); - } else if (!paused && m_state == QMediaPlayer::PausedState) { + } + else if (!m_paused && m_playing) { m_playerControl->play(); - } else { - m_paused = paused; - - emit pausedChanged(); } } + + emit pausedChanged(); } int QDeclarativeMediaBase::duration() const { - return m_playerControl->duration(); + return m_playerControl == 0 ? 0 : m_playerControl->duration(); } int QDeclarativeMediaBase::position() const { - return m_playerControl->position(); - + return m_playerControl == 0 ? m_position : m_playerControl->position(); } void QDeclarativeMediaBase::setPosition(int position) { - m_playerControl->setPosition(position); + if (m_position == position) + return; + + m_position = position; + if (m_playerControl != 0) + m_playerControl->setPosition(m_position); + else + emit positionChanged(); } qreal QDeclarativeMediaBase::volume() const { - return qreal(m_playerControl->volume()) / 100; + return m_playerControl == 0 ? m_volume : qreal(m_playerControl->volume()) / 100; } void QDeclarativeMediaBase::setVolume(qreal volume) { - m_playerControl->setVolume(qRound(volume * 100)); + if (m_volume == volume) + return; + + m_volume = volume; + + if (m_playerControl != 0) + m_playerControl->setVolume(qRound(volume * 100)); + else + emit volumeChanged(); } bool QDeclarativeMediaBase::isMuted() const { - return m_playerControl->isMuted(); + return m_playerControl == 0 ? m_muted : m_playerControl->isMuted(); } void QDeclarativeMediaBase::setMuted(bool muted) { - m_playerControl->setMuted(muted); + if (m_muted == muted) + return; + + m_muted = muted; + + if (m_playerControl != 0) + m_playerControl->setMuted(muted); + else + emit mutedChanged(); } qreal QDeclarativeMediaBase::bufferProgress() const { - return qreal(m_playerControl->bufferStatus()) / 100; + return m_playerControl == 0 ? 0 : qreal(m_playerControl->bufferStatus()) / 100; } bool QDeclarativeMediaBase::isSeekable() const { - return m_playerControl->isSeekable(); + return m_playerControl == 0 ? false : m_playerControl->isSeekable(); } qreal QDeclarativeMediaBase::playbackRate() const { - return m_playerControl->playbackRate(); + return m_playbackRate; } void QDeclarativeMediaBase::setPlaybackRate(qreal rate) { - m_playerControl->setPlaybackRate(rate); + if (m_playbackRate == rate) + return; + + m_playbackRate = rate; + + if (m_playerControl != 0) + m_playerControl->setPlaybackRate(m_playbackRate); + else + emit playbackRateChanged(); } QString QDeclarativeMediaBase::errorString() const diff --git a/src/imports/multimedia/qdeclarativemediabase_p.h b/src/imports/multimedia/qdeclarativemediabase_p.h index b40e84e..d279f4a 100644 --- a/src/imports/multimedia/qdeclarativemediabase_p.h +++ b/src/imports/multimedia/qdeclarativemediabase_p.h @@ -107,13 +107,14 @@ public: void _q_metaDataChanged(); + void componentComplete(); + protected: void shutdown(); void setObject(QObject *object); virtual void sourceChanged() = 0; - virtual void playingChanged() = 0; virtual void pausedChanged() = 0; @@ -143,6 +144,12 @@ protected: virtual void errorChanged() = 0; + bool m_paused; + bool m_playing; + bool m_muted; + int m_position; + qreal m_volume; + qreal m_playbackRate; QMediaService *m_mediaService; QMediaPlayerControl *m_playerControl; @@ -155,8 +162,8 @@ protected: QMediaPlayer::State m_state; QMediaPlayer::MediaStatus m_status; QMediaPlayer::Error m_error; - bool m_paused; QString m_errorString; + QUrl m_source; friend class QDeclarativeMediaBaseAnimation; }; diff --git a/src/imports/multimedia/qdeclarativevideo.cpp b/src/imports/multimedia/qdeclarativevideo.cpp index 80c0ba4..67d9aef 100644 --- a/src/imports/multimedia/qdeclarativevideo.cpp +++ b/src/imports/multimedia/qdeclarativevideo.cpp @@ -100,17 +100,6 @@ QDeclarativeVideo::QDeclarativeVideo(QDeclarativeItem *parent) m_graphicsItem = new QGraphicsVideoItem(this); connect(m_graphicsItem, SIGNAL(nativeSizeChanged(QSizeF)), this, SLOT(_q_nativeSizeChanged(QSizeF))); - - setObject(this); - - if (m_mediaService) { - connect(m_playerControl, SIGNAL(audioAvailableChanged(bool)), - this, SIGNAL(hasAudioChanged())); - connect(m_playerControl, SIGNAL(videoAvailableChanged(bool)), - this, SIGNAL(hasVideoChanged())); - - m_graphicsItem->setMediaObject(m_mediaObject); - } } QDeclarativeVideo::~QDeclarativeVideo() @@ -253,7 +242,7 @@ QDeclarativeVideo::Status QDeclarativeVideo::status() const bool QDeclarativeVideo::hasAudio() const { - return m_playerControl->isAudioAvailable(); + return m_playerControl == 0 ? false : m_playerControl->isAudioAvailable(); } /*! @@ -264,7 +253,7 @@ bool QDeclarativeVideo::hasAudio() const bool QDeclarativeVideo::hasVideo() const { - return m_playerControl->isVideoAvailable(); + return m_playerControl == 0 ? false : m_playerControl->isVideoAvailable(); } /*! @@ -356,12 +345,11 @@ void QDeclarativeVideo::setFillMode(FillMode mode) void QDeclarativeVideo::play() { - m_playerControl->play(); + if (m_playerControl == 0) + return; - if (m_paused) { - m_paused = false; - emit pausedChanged(); - } + setPaused(false); + setPlaying(true); } /*! @@ -374,12 +362,11 @@ void QDeclarativeVideo::play() void QDeclarativeVideo::pause() { - m_playerControl->pause(); + if (m_playerControl == 0) + return; - if (!m_paused && m_state == QMediaPlayer::PausedState) { - m_paused = true; - emit pausedChanged(); - } + setPaused(true); + setPlaying(true); } /*! @@ -392,12 +379,11 @@ void QDeclarativeVideo::pause() void QDeclarativeVideo::stop() { - m_playerControl->stop(); + if (m_playerControl == 0) + return; - if (m_paused) { - m_paused = false; - emit pausedChanged(); - } + setPlaying(false); + setPaused(false); } void QDeclarativeVideo::paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) @@ -411,6 +397,20 @@ void QDeclarativeVideo::geometryChanged(const QRectF &newGeometry, const QRectF QDeclarativeItem::geometryChanged(newGeometry, oldGeometry); } +void QDeclarativeVideo::componentComplete() +{ + setObject(this); + + if (m_mediaService) { + connect(m_playerControl, SIGNAL(audioAvailableChanged(bool)), + this, SIGNAL(hasAudioChanged())); + connect(m_playerControl, SIGNAL(videoAvailableChanged(bool)), + this, SIGNAL(hasVideoChanged())); + + m_graphicsItem->setMediaObject(m_mediaObject); + } +} + QT_END_NAMESPACE // *************************************** diff --git a/src/imports/multimedia/qdeclarativevideo_p.h b/src/imports/multimedia/qdeclarativevideo_p.h index fb13519..2dead2e 100644 --- a/src/imports/multimedia/qdeclarativevideo_p.h +++ b/src/imports/multimedia/qdeclarativevideo_p.h @@ -136,6 +136,8 @@ public: void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); + void componentComplete(); + public Q_SLOTS: void play(); void pause(); |