Init mediaobject at classBegin rather than componentComplete

Since we use an explicit backgroundaudio class,
there is no need to wait for other property to determine
the mediaobject type. So it is better to init the mediaobject
at classBegin to prevent being accessed before mediaobject initialized.

Change-Id: Ia55b8b4c1ab70cc0acbf6f49bcb3e20bdb813a88
Reviewed-by: Michael Goddard <michael.goddard@nokia.com>
Reviewed-by: Jonas Rabbe <jonas.rabbe@nokia.com>
Reviewed-by: Dmytro Poplavskiy <dmytro.poplavskiy@nokia.com>
This commit is contained in:
Ling Hu
2011-10-14 10:36:49 +10:00
committed by Qt by Nokia
parent d414247afe
commit 9011296e65

View File

@@ -43,10 +43,6 @@
#include <qmediaservice.h> #include <qmediaservice.h>
void QDeclarativeBackgroundAudio::classBegin() void QDeclarativeBackgroundAudio::classBegin()
{
}
void QDeclarativeBackgroundAudio::componentComplete()
{ {
setObject(this, Q_MEDIASERVICE_BACKGROUNDMEDIAPLAYER); setObject(this, Q_MEDIASERVICE_BACKGROUNDMEDIAPLAYER);
if (m_mediaService) { if (m_mediaService) {
@@ -56,15 +52,21 @@ void QDeclarativeBackgroundAudio::componentComplete()
if (m_backgroundPlaybackControl) { if (m_backgroundPlaybackControl) {
connect(m_backgroundPlaybackControl, SIGNAL(acquired()), this, SIGNAL(acquiredChanged())); connect(m_backgroundPlaybackControl, SIGNAL(acquired()), this, SIGNAL(acquiredChanged()));
connect(m_backgroundPlaybackControl, SIGNAL(lost()), this, SIGNAL(acquiredChanged())); connect(m_backgroundPlaybackControl, SIGNAL(lost()), this, SIGNAL(acquiredChanged()));
if (!m_contextId.isEmpty())
m_backgroundPlaybackControl->setContextId(m_contextId);
} else { } else {
qWarning("can not get QMediaBackgroundPlaybackControl!"); qWarning("can not get QMediaBackgroundPlaybackControl!");
} }
} else { } else {
qWarning("Unable to get any background mediaplayer!"); qWarning("Unable to get any background mediaplayer!");
} }
QDeclarativeMediaBase::componentComplete(); emit mediaObjectChanged();
//Note: we are not calling QDeclarativeAudio::classBegin here,
//otherwise there will be conflict for setObject().
}
void QDeclarativeBackgroundAudio::componentComplete()
{
QDeclarativeAudio::componentComplete();
} }
QDeclarativeBackgroundAudio::QDeclarativeBackgroundAudio(QObject *parent) QDeclarativeBackgroundAudio::QDeclarativeBackgroundAudio(QObject *parent)