diff options
author | Qt Continuous Integration System <qt-info@nokia.com> | 2010-03-19 07:37:06 (GMT) |
---|---|---|
committer | Qt Continuous Integration System <qt-info@nokia.com> | 2010-03-19 07:37:06 (GMT) |
commit | 71dedbee1f5a23411e2c82157a6fe6ee5d48ab6e (patch) | |
tree | 67cc84ebcc6342e4b50432b009f21e832efb5f85 /src/imports/multimedia | |
parent | b6e874a0f56e1d81cc2ad355d3dc9e92fd96ddd2 (diff) | |
parent | ace866a969cd438b9f1dc11b7d40a99f53a13009 (diff) | |
download | Qt-71dedbee1f5a23411e2c82157a6fe6ee5d48ab6e.zip Qt-71dedbee1f5a23411e2c82157a6fe6ee5d48ab6e.tar.gz Qt-71dedbee1f5a23411e2c82157a6fe6ee5d48ab6e.tar.bz2 |
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/qt-multimedia-staging into 4.7-integration
* '4.7' of scm.dev.nokia.troll.no:qt/qt-multimedia-staging:
Add autoLoad property to multimedia declarative elements.
Fix; QML Video item is sensitive to property assignment order
Diffstat (limited to 'src/imports/multimedia')
-rw-r--r-- | src/imports/multimedia/qdeclarativeaudio.cpp | 44 | ||||
-rw-r--r-- | src/imports/multimedia/qdeclarativeaudio_p.h | 5 | ||||
-rw-r--r-- | src/imports/multimedia/qdeclarativemediabase.cpp | 247 | ||||
-rw-r--r-- | src/imports/multimedia/qdeclarativemediabase_p.h | 17 | ||||
-rw-r--r-- | src/imports/multimedia/qdeclarativevideo.cpp | 64 | ||||
-rw-r--r-- | src/imports/multimedia/qdeclarativevideo_p.h | 5 |
6 files changed, 267 insertions, 115 deletions
diff --git a/src/imports/multimedia/qdeclarativeaudio.cpp b/src/imports/multimedia/qdeclarativeaudio.cpp index 40133ee..dfe125f 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); } /*! @@ -146,6 +142,14 @@ void QDeclarativeAudio::stop() */ /*! + \qmlproperty url Audio:autoLoad + + This property indicates if loading of media should begin immediately. + + Defaults to true, if false media will not be loaded until playback is started. +*/ + +/*! \qmlproperty bool Audio::playing This property holds whether the media is playing. @@ -307,6 +311,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..24276ea 100644 --- a/src/imports/multimedia/qdeclarativeaudio_p.h +++ b/src/imports/multimedia/qdeclarativeaudio_p.h @@ -69,6 +69,7 @@ class QDeclarativeAudio : public QObject, public QDeclarativeMediaBase, public Q { Q_OBJECT Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) + Q_PROPERTY(bool autoLoad READ isAutoLoad WRITE setAutoLoad NOTIFY autoLoadChanged) Q_PROPERTY(bool playing READ isPlaying WRITE setPlaying NOTIFY playingChanged) Q_PROPERTY(bool paused READ isPaused WRITE setPaused NOTIFY pausedChanged) Q_PROPERTY(Status status READ status NOTIFY statusChanged) @@ -114,6 +115,8 @@ public: Status status() const; Error error() const; + void componentComplete(); + public Q_SLOTS: void play(); void pause(); @@ -121,7 +124,7 @@ public Q_SLOTS: Q_SIGNALS: void sourceChanged(); - + void autoLoadChanged(); void playingChanged(); void pausedChanged(); diff --git a/src/imports/multimedia/qdeclarativemediabase.cpp b/src/imports/multimedia/qdeclarativemediabase.cpp index 8e87e44..5bad969 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,15 @@ void QDeclarativeMediaBase::_q_metaDataChanged() } QDeclarativeMediaBase::QDeclarativeMediaBase() - : m_mediaService(0) + : m_paused(false) + , m_playing(false) + , m_autoLoad(true) + , m_loaded(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 +243,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 +300,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 +311,97 @@ 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_autoLoad || m_playing)) // Override autoLoad if playing set + m_playerControl->setMedia(m_source, 0); + + if (m_paused) + m_playerControl->pause(); + else if (m_playing) + m_playerControl->play(); + + if ((m_playing || m_paused) && 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; + m_loaded = false; + if (m_playerControl != 0 && m_autoLoad) { + if (m_error != QMediaPlayer::ServiceMissingError && m_error != QMediaPlayer::NoError) { + m_error = QMediaPlayer::NoError; + m_errorString = QString(); + + emit errorChanged(); + } + + m_playerControl->setMedia(m_source, 0); + m_loaded = true; } + else + emit sourceChanged(); +} - m_playerControl->setMedia(QMediaContent(url), 0); +bool QDeclarativeMediaBase::isAutoLoad() const +{ + return m_autoLoad; +} + +void QDeclarativeMediaBase::setAutoLoad(bool autoLoad) +{ + if (m_autoLoad == autoLoad) + return; + + m_autoLoad = autoLoad; + emit autoLoadChanged(); } 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_autoLoad && !m_loaded) { + m_playerControl->setMedia(m_source, 0); + m_playerControl->setPosition(m_position); + m_loaded = true; + } + + 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 +411,112 @@ 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) { + if (!m_autoLoad && !m_loaded) { + m_playerControl->setMedia(m_source, 0); + m_playerControl->setPosition(m_position); + m_loaded = true; + } + + 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..43df54d 100644 --- a/src/imports/multimedia/qdeclarativemediabase_p.h +++ b/src/imports/multimedia/qdeclarativemediabase_p.h @@ -76,6 +76,9 @@ public: QUrl source() const; void setSource(const QUrl &url); + bool isAutoLoad() const; + void setAutoLoad(bool autoLoad); + bool isPlaying() const; void setPlaying(bool playing); @@ -107,13 +110,15 @@ public: void _q_metaDataChanged(); + void componentComplete(); + protected: void shutdown(); void setObject(QObject *object); virtual void sourceChanged() = 0; - + virtual void autoLoadChanged() = 0; virtual void playingChanged() = 0; virtual void pausedChanged() = 0; @@ -143,6 +148,14 @@ protected: virtual void errorChanged() = 0; + bool m_paused; + bool m_playing; + bool m_autoLoad; + bool m_loaded; + bool m_muted; + int m_position; + qreal m_volume; + qreal m_playbackRate; QMediaService *m_mediaService; QMediaPlayerControl *m_playerControl; @@ -155,8 +168,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..6aff9bd 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() @@ -127,6 +116,14 @@ QDeclarativeVideo::~QDeclarativeVideo() */ /*! + \qmlproperty url Audio:autoLoad + + This property indicates if loading of media should begin immediately. + + Defaults to true, if false media will not be loaded until playback is started. +*/ + +/*! \qmlproperty bool Video::playing This property holds whether the media is playing. @@ -253,7 +250,7 @@ QDeclarativeVideo::Status QDeclarativeVideo::status() const bool QDeclarativeVideo::hasAudio() const { - return m_playerControl->isAudioAvailable(); + return m_playerControl == 0 ? false : m_playerControl->isAudioAvailable(); } /*! @@ -264,7 +261,7 @@ bool QDeclarativeVideo::hasAudio() const bool QDeclarativeVideo::hasVideo() const { - return m_playerControl->isVideoAvailable(); + return m_playerControl == 0 ? false : m_playerControl->isVideoAvailable(); } /*! @@ -356,12 +353,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 +370,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 +387,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 +405,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..29e1090 100644 --- a/src/imports/multimedia/qdeclarativevideo_p.h +++ b/src/imports/multimedia/qdeclarativevideo_p.h @@ -73,6 +73,7 @@ class QDeclarativeVideo : public QDeclarativeItem, public QDeclarativeMediaBase { Q_OBJECT Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) + Q_PROPERTY(bool autoLoad READ isAutoLoad WRITE setAutoLoad NOTIFY autoLoadChanged) Q_PROPERTY(bool playing READ isPlaying WRITE setPlaying NOTIFY playingChanged) Q_PROPERTY(bool paused READ isPaused WRITE setPaused NOTIFY pausedChanged) Q_PROPERTY(Status status READ status NOTIFY statusChanged) @@ -136,6 +137,8 @@ public: void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); + void componentComplete(); + public Q_SLOTS: void play(); void pause(); @@ -143,7 +146,7 @@ public Q_SLOTS: Q_SIGNALS: void sourceChanged(); - + void autoLoadChanged(); void playingChanged(); void pausedChanged(); |