diff options
author | Justin McPherson <justin.mcpherson@nokia.com> | 2010-03-19 04:25:45 (GMT) |
---|---|---|
committer | Justin McPherson <justin.mcpherson@nokia.com> | 2010-03-19 05:32:17 (GMT) |
commit | ace866a969cd438b9f1dc11b7d40a99f53a13009 (patch) | |
tree | 723d5855bceb2d0b6aa755c7a85395b2db6292cd /src/imports/multimedia | |
parent | 0d4572595698502e04f491bfea3e16bb1851b645 (diff) | |
download | Qt-ace866a969cd438b9f1dc11b7d40a99f53a13009.zip Qt-ace866a969cd438b9f1dc11b7d40a99f53a13009.tar.gz Qt-ace866a969cd438b9f1dc11b7d40a99f53a13009.tar.bz2 |
Add autoLoad property to multimedia declarative elements.
Task-number: QTBUG-8947
Reviewed-by: Andrew den Exter
Diffstat (limited to 'src/imports/multimedia')
-rw-r--r-- | src/imports/multimedia/qdeclarativeaudio.cpp | 8 | ||||
-rw-r--r-- | src/imports/multimedia/qdeclarativeaudio_p.h | 3 | ||||
-rw-r--r-- | src/imports/multimedia/qdeclarativemediabase.cpp | 42 | ||||
-rw-r--r-- | src/imports/multimedia/qdeclarativemediabase_p.h | 6 | ||||
-rw-r--r-- | src/imports/multimedia/qdeclarativevideo.cpp | 8 | ||||
-rw-r--r-- | src/imports/multimedia/qdeclarativevideo_p.h | 3 |
6 files changed, 62 insertions, 8 deletions
diff --git a/src/imports/multimedia/qdeclarativeaudio.cpp b/src/imports/multimedia/qdeclarativeaudio.cpp index 39223dc..dfe125f 100644 --- a/src/imports/multimedia/qdeclarativeaudio.cpp +++ b/src/imports/multimedia/qdeclarativeaudio.cpp @@ -142,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. diff --git a/src/imports/multimedia/qdeclarativeaudio_p.h b/src/imports/multimedia/qdeclarativeaudio_p.h index 2e8ae30..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) @@ -123,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 542c931..5bad969 100644 --- a/src/imports/multimedia/qdeclarativemediabase.cpp +++ b/src/imports/multimedia/qdeclarativemediabase.cpp @@ -228,6 +228,8 @@ void QDeclarativeMediaBase::_q_metaDataChanged() QDeclarativeMediaBase::QDeclarativeMediaBase() : m_paused(false) , m_playing(false) + , m_autoLoad(true) + , m_loaded(false) , m_muted(false) , m_position(0) , m_volume(1.0) @@ -315,13 +317,15 @@ void QDeclarativeMediaBase::setObject(QObject *object) m_playerControl->setMuted(m_muted); m_playerControl->setPlaybackRate(m_playbackRate); - if (!m_source.isEmpty()) + if (!m_source.isEmpty() && (m_autoLoad || m_playing)) // Override autoLoad if playing set m_playerControl->setMedia(m_source, 0); - if (m_playing) + if (m_paused) + m_playerControl->pause(); + else if (m_playing) m_playerControl->play(); - if (m_position > 0) + if ((m_playing || m_paused) && m_position > 0) m_playerControl->setPosition(m_position); } @@ -339,8 +343,8 @@ void QDeclarativeMediaBase::setSource(const QUrl &url) return; m_source = url; - - if (m_playerControl != 0) { + 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(); @@ -349,11 +353,26 @@ void QDeclarativeMediaBase::setSource(const QUrl &url) } m_playerControl->setMedia(m_source, 0); + m_loaded = true; } else emit sourceChanged(); } +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_playing; @@ -367,6 +386,12 @@ void QDeclarativeMediaBase::setPlaying(bool playing) 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 @@ -391,7 +416,12 @@ void QDeclarativeMediaBase::setPaused(bool paused) m_paused = paused; if (m_playerControl != 0) { - // Check if completed, change state + 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(); } diff --git a/src/imports/multimedia/qdeclarativemediabase_p.h b/src/imports/multimedia/qdeclarativemediabase_p.h index d279f4a..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); @@ -115,6 +118,7 @@ protected: void setObject(QObject *object); virtual void sourceChanged() = 0; + virtual void autoLoadChanged() = 0; virtual void playingChanged() = 0; virtual void pausedChanged() = 0; @@ -146,6 +150,8 @@ protected: bool m_paused; bool m_playing; + bool m_autoLoad; + bool m_loaded; bool m_muted; int m_position; qreal m_volume; diff --git a/src/imports/multimedia/qdeclarativevideo.cpp b/src/imports/multimedia/qdeclarativevideo.cpp index 67d9aef..6aff9bd 100644 --- a/src/imports/multimedia/qdeclarativevideo.cpp +++ b/src/imports/multimedia/qdeclarativevideo.cpp @@ -116,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. diff --git a/src/imports/multimedia/qdeclarativevideo_p.h b/src/imports/multimedia/qdeclarativevideo_p.h index 2dead2e..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) @@ -145,7 +146,7 @@ public Q_SLOTS: Q_SIGNALS: void sourceChanged(); - + void autoLoadChanged(); void playingChanged(); void pausedChanged(); |