qtmobility/plugins/multimedia/symbian/mmf/mediaplayer/s60audioplayersession.cpp
changeset 5 453da2cfceef
parent 4 90517678cc4f
child 11 06b8e2af4411
--- a/qtmobility/plugins/multimedia/symbian/mmf/mediaplayer/s60audioplayersession.cpp	Mon May 03 13:18:40 2010 +0300
+++ b/qtmobility/plugins/multimedia/symbian/mmf/mediaplayer/s60audioplayersession.cpp	Fri May 14 16:41:33 2010 +0300
@@ -50,17 +50,15 @@
     : S60MediaPlayerSession(parent)
     , m_player(0)
     , m_audioOutput(0)
+    , m_audioEndpoint("Default")
 {
     QT_TRAP_THROWING(m_player = CAudioPlayer::NewL(*this, 0, EMdaPriorityPreferenceNone));
-    //QT_TRAP_THROWING(m_audioOutput = CAudioOutput::NewL(*m_player));
-    //QT_TRAP_THROWING(m_audioOutput->RegisterObserverL(*this));
-
     m_player->RegisterForAudioLoadingNotification(*this);
 }
 
 S60AudioPlayerSession::~S60AudioPlayerSession()
 {
-#ifndef HAS_NO_AUDIOROUTING
+#if !defined(HAS_NO_AUDIOROUTING)
     if (m_audioOutput)
         m_audioOutput->UnregisterObserver(*this);
     delete m_audioOutput;
@@ -71,6 +69,12 @@
 
 void S60AudioPlayerSession::doLoadL(const TDesC &path)
 {
+    // m_audioOutput needs to be reinitialized after MapcInitComplete
+    if (m_audioOutput)
+        m_audioOutput->UnregisterObserver(*this);
+    delete m_audioOutput;
+    m_audioOutput = NULL;
+
     m_player->OpenFileL(path);
 }
 
@@ -169,6 +173,12 @@
 {
     Q_UNUSED(aDuration);
     setError(aError);
+    TRAPD(err, 
+        m_audioOutput = CAudioOutput::NewL(*m_player);
+        m_audioOutput->RegisterObserverL(*this);
+    );
+    setActiveEndpoint(m_audioEndpoint);
+    setError(err);
     loaded();
 }
 
@@ -182,30 +192,33 @@
     endOfMedia();
 }
 
+void S60AudioPlayerSession::doSetAudioEndpoint(const QString& audioEndpoint)
+{
+    m_audioEndpoint = audioEndpoint;
+}
+
 QString S60AudioPlayerSession::activeEndpoint() const
 {
-#ifndef HAS_NO_AUDIOROUTING
-    QString outputName;
+    QString outputName = QString("Default");
+#if !defined(HAS_NO_AUDIOROUTING)
     if (m_audioOutput) {
         CAudioOutput::TAudioOutputPreference output = m_audioOutput->AudioOutput();
         outputName = qStringFromTAudioOutputPreference(output);
     }
+#endif
     return outputName;
-#endif
-    return QString("Default");
 }
 
 QString S60AudioPlayerSession::defaultEndpoint() const
 {
-#ifndef HAS_NO_AUDIOROUTING
-    QString outputName;
+    QString outputName = QString("Default");
+#if !defined(HAS_NO_AUDIOROUTING)
     if (m_audioOutput) {
         CAudioOutput::TAudioOutputPreference output = m_audioOutput->DefaultAudioOutput();
         outputName = qStringFromTAudioOutputPreference(output);
     }
+#endif
     return outputName;
-#endif
-    return QString("Default");
 }
 
 void S60AudioPlayerSession::setActiveEndpoint(const QString& name)
@@ -222,39 +235,25 @@
         output = CAudioOutput::EPrivate;
     else if (name == QString("Speaker"))
         output = CAudioOutput::EPublic;
-#ifndef HAS_NO_AUDIOROUTING
+#if !defined(HAS_NO_AUDIOROUTING)
     if (m_audioOutput) {
         TRAPD(err, m_audioOutput->SetAudioOutputL(output));
         setError(err);
+
+        if (m_audioEndpoint != name) {
+            m_audioEndpoint = name;
+            emit activeEndpointChanged(name);
+        }
     }
 #endif
-
 }
 
 void S60AudioPlayerSession::DefaultAudioOutputChanged(CAudioOutput& aAudioOutput,
                                         CAudioOutput::TAudioOutputPreference aNewDefault)
 {
-#ifndef HAS_NO_AUDIOROUTING
-    if (m_audioOutput) {
-        CAudioOutput::TAudioOutputPreference output = m_audioOutput->AudioOutput();
-        if (output == CAudioOutput::ENoPreference) {
-            QString name;
-            if (output == CAudioOutput::EAll)
-                name = QString("All");
-            else if (output == CAudioOutput::ENoOutput)
-                name = QString("None");
-            else if (output == CAudioOutput::EPrivate)
-                name = QString("Earphone");
-            else if (output == CAudioOutput::EPublic)
-                name = QString("Speaker");
-            if (!name.isEmpty())
-                emit activeEndpointChanged(name);
-        }
-    }
-#else
+    // Emit already implemented in setActiveEndpoint function
     Q_UNUSED(aAudioOutput)
     Q_UNUSED(aNewDefault)
-#endif
 }
 
 QString S60AudioPlayerSession::qStringFromTAudioOutputPreference(CAudioOutput::TAudioOutputPreference output) const
@@ -264,10 +263,10 @@
     else if (output == CAudioOutput::EAll)
         return QString("All");
     else if (output == CAudioOutput::ENoOutput)
-            return QString("None");
+        return QString("None");
     else if (output == CAudioOutput::EPrivate)
-            return QString("Earphone");
+        return QString("Earphone");
     else if (output == CAudioOutput::EPublic)
-            return QString("Speaker");
-    return QString();
+        return QString("Speaker");
+    return QString("Default");
 }