Fix some MediaPlayer properties returning wrong values.
authorYoann Lopes <yoann.lopes@digia.com>
Tue, 8 Apr 2014 16:50:23 +0000 (18:50 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Wed, 9 Apr 2014 12:48:49 +0000 (14:48 +0200)
Once the QML component is complete, don't cache any value anymore and
always ask the backend for the actual value.

Change-Id: I2c3ad55618e0532f713cfcc8258a70a1114fc975
Reviewed-by: Christian Stromme <christian.stromme@digia.com>
src/imports/multimedia/qdeclarativeaudio.cpp
tests/auto/unit/qdeclarativeaudio/tst_qdeclarativeaudio.cpp

index 16828a4..37509b1 100644 (file)
@@ -290,15 +290,15 @@ void QDeclarativeAudio::setVolume(qreal volume)
         return;
     }
 
-    if (m_vol == volume)
+    if (this->volume() == volume)
         return;
 
-    m_vol = volume;
-
-    if (m_complete)
+    if (m_complete) {
         m_player->setVolume(qRound(volume * 100));
-    else
+    } else {
+        m_vol = volume;
         emit volumeChanged();
+    }
 }
 
 bool QDeclarativeAudio::isMuted() const
@@ -308,15 +308,15 @@ bool QDeclarativeAudio::isMuted() const
 
 void QDeclarativeAudio::setMuted(bool muted)
 {
-    if (m_muted == muted)
+    if (isMuted() == muted)
         return;
 
-    m_muted = muted;
-
-    if (m_complete)
+    if (m_complete) {
         m_player->setMuted(muted);
-    else
+    } else {
+        m_muted = muted;
         emit mutedChanged();
+    }
 }
 
 qreal QDeclarativeAudio::bufferProgress() const
@@ -331,20 +331,20 @@ bool QDeclarativeAudio::isSeekable() const
 
 qreal QDeclarativeAudio::playbackRate() const
 {
-    return m_playbackRate;
+    return m_complete ? m_player->playbackRate() : m_playbackRate;
 }
 
 void QDeclarativeAudio::setPlaybackRate(qreal rate)
 {
-    if (m_playbackRate == rate)
+    if (playbackRate() == rate)
         return;
 
-    m_playbackRate = rate;
-
-    if (m_complete)
-        m_player->setPlaybackRate(m_playbackRate);
-    else
+    if (m_complete) {
+        m_player->setPlaybackRate(rate);
+    } else {
+        m_playbackRate = rate;
         emit playbackRateChanged();
+    }
 }
 
 QString QDeclarativeAudio::errorString() const
@@ -426,12 +426,12 @@ void QDeclarativeAudio::seek(int position)
     if (this->position() == position)
         return;
 
-    m_position = position;
-
-    if (m_complete)
-        m_player->setPosition(m_position);
-    else
+    if (m_complete) {
+        m_player->setPosition(position);
+    } else {
+        m_position = position;
         emit positionChanged();
+    }
 }
 
 /*!
index 57f820b..fb946d7 100644 (file)
@@ -777,7 +777,7 @@ void tst_QDeclarativeAudio::playbackRate()
     audio.setPlaybackRate(2.0);
     QCOMPARE(audio.playbackRate(), qreal(2.0));
     QCOMPARE(provider.playerControl()->playbackRate(), qreal(2.0));
-    QCOMPARE(spy.count(), 3);
+    QCOMPARE(spy.count(), 2);
 }
 
 void tst_QDeclarativeAudio::status()