qtmobility/plugins/multimedia/symbian/mmf/mediaplayer/s60audioplayersession.cpp
changeset 4 90517678cc4f
child 5 453da2cfceef
equal deleted inserted replaced
1:2b40d63a9c3d 4:90517678cc4f
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the Qt Mobility Components.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #include "s60audioplayersession.h"
       
    43 #include <QtCore/qdebug.h>
       
    44 #include <QtCore/qvariant.h>
       
    45 
       
    46 #include <AudioOutput.h>
       
    47 #include <MAudioOutputObserver.h>
       
    48 
       
    49 S60AudioPlayerSession::S60AudioPlayerSession(QObject *parent)
       
    50     : S60MediaPlayerSession(parent)
       
    51     , m_player(0)
       
    52     , m_audioOutput(0)
       
    53 {
       
    54     QT_TRAP_THROWING(m_player = CAudioPlayer::NewL(*this, 0, EMdaPriorityPreferenceNone));
       
    55     //QT_TRAP_THROWING(m_audioOutput = CAudioOutput::NewL(*m_player));
       
    56     //QT_TRAP_THROWING(m_audioOutput->RegisterObserverL(*this));
       
    57 
       
    58     m_player->RegisterForAudioLoadingNotification(*this);
       
    59 }
       
    60 
       
    61 S60AudioPlayerSession::~S60AudioPlayerSession()
       
    62 {
       
    63 #ifndef HAS_NO_AUDIOROUTING
       
    64     if (m_audioOutput)
       
    65         m_audioOutput->UnregisterObserver(*this);
       
    66     delete m_audioOutput;
       
    67 #endif
       
    68     m_player->Close();
       
    69     delete m_player;
       
    70 }
       
    71 
       
    72 void S60AudioPlayerSession::doLoadL(const TDesC &path)
       
    73 {
       
    74     m_player->OpenFileL(path);
       
    75 }
       
    76 
       
    77 qint64 S60AudioPlayerSession::doGetDurationL() const
       
    78 {
       
    79     return m_player->Duration().Int64() / qint64(1000);
       
    80 }
       
    81 
       
    82 qint64 S60AudioPlayerSession::doGetPositionL() const
       
    83 {
       
    84     TTimeIntervalMicroSeconds ms = 0;
       
    85     m_player->GetPosition(ms);
       
    86     return ms.Int64() / qint64(1000);
       
    87 }
       
    88 
       
    89 bool S60AudioPlayerSession::isVideoAvailable() const
       
    90 {
       
    91     return false;
       
    92 }
       
    93 bool S60AudioPlayerSession::isAudioAvailable() const
       
    94 {
       
    95     return true; // this is a bit happy scenario, but we do emit error that we can't play
       
    96 }
       
    97 
       
    98 void S60AudioPlayerSession::MaloLoadingStarted()
       
    99 {
       
   100     buffering();
       
   101 }
       
   102 
       
   103 void S60AudioPlayerSession::MaloLoadingComplete()
       
   104 {
       
   105     buffered();
       
   106 }
       
   107 
       
   108 void S60AudioPlayerSession::doPlay()
       
   109 {
       
   110 // For some reason loading progress callbalck are not called on emulator
       
   111 #ifdef __WINSCW__
       
   112     buffering();
       
   113 #endif
       
   114     m_player->Play();
       
   115 #ifdef __WINSCW__
       
   116     buffered();
       
   117 #endif
       
   118 
       
   119 }
       
   120 
       
   121 void S60AudioPlayerSession::doPauseL()
       
   122 {
       
   123     m_player->Pause();
       
   124 }
       
   125 
       
   126 void S60AudioPlayerSession::doStop()
       
   127 {
       
   128     m_player->Stop();
       
   129 }
       
   130 
       
   131 void S60AudioPlayerSession::doSetVolumeL(int volume)
       
   132 {
       
   133     m_player->SetVolume((volume / 100.0) * m_player->MaxVolume());
       
   134 }
       
   135 
       
   136 void S60AudioPlayerSession::doSetPositionL(qint64 microSeconds)
       
   137 {
       
   138     m_player->SetPosition(TTimeIntervalMicroSeconds(microSeconds));
       
   139 }
       
   140 
       
   141 void S60AudioPlayerSession::updateMetaDataEntriesL()
       
   142 {
       
   143     metaDataEntries().clear();
       
   144     int numberOfMetaDataEntries = 0;
       
   145 
       
   146     m_player->GetNumberOfMetaDataEntries(numberOfMetaDataEntries);
       
   147 
       
   148     for (int i = 0; i < numberOfMetaDataEntries; i++) {
       
   149         CMMFMetaDataEntry *entry = NULL;
       
   150         entry = m_player->GetMetaDataEntryL(i);
       
   151         metaDataEntries().insert(QString::fromUtf16(entry->Name().Ptr(), entry->Name().Length()), QString::fromUtf16(entry->Value().Ptr(), entry->Value().Length()));
       
   152         delete entry;
       
   153     }
       
   154     emit metaDataChanged();
       
   155 }
       
   156 
       
   157 int S60AudioPlayerSession::doGetBufferStatusL() const
       
   158 {
       
   159     int progress = 0;
       
   160     m_player->GetAudioLoadingProgressL(progress);
       
   161     return progress;
       
   162 }
       
   163 
       
   164 #ifdef S60_DRM_SUPPORTED
       
   165 void S60AudioPlayerSession::MdapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& aDuration)
       
   166 #else
       
   167 void S60AudioPlayerSession::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& aDuration)
       
   168 #endif
       
   169 {
       
   170     Q_UNUSED(aDuration);
       
   171     setError(aError);
       
   172     loaded();
       
   173 }
       
   174 
       
   175 #ifdef S60_DRM_SUPPORTED
       
   176 void S60AudioPlayerSession::MdapcPlayComplete(TInt aError)
       
   177 #else
       
   178 void S60AudioPlayerSession::MapcPlayComplete(TInt aError)
       
   179 #endif
       
   180 {
       
   181     setError(aError);
       
   182     endOfMedia();
       
   183 }
       
   184 
       
   185 QString S60AudioPlayerSession::activeEndpoint() const
       
   186 {
       
   187 #ifndef HAS_NO_AUDIOROUTING
       
   188     QString outputName;
       
   189     if (m_audioOutput) {
       
   190         CAudioOutput::TAudioOutputPreference output = m_audioOutput->AudioOutput();
       
   191         outputName = qStringFromTAudioOutputPreference(output);
       
   192     }
       
   193     return outputName;
       
   194 #endif
       
   195     return QString("Default");
       
   196 }
       
   197 
       
   198 QString S60AudioPlayerSession::defaultEndpoint() const
       
   199 {
       
   200 #ifndef HAS_NO_AUDIOROUTING
       
   201     QString outputName;
       
   202     if (m_audioOutput) {
       
   203         CAudioOutput::TAudioOutputPreference output = m_audioOutput->DefaultAudioOutput();
       
   204         outputName = qStringFromTAudioOutputPreference(output);
       
   205     }
       
   206     return outputName;
       
   207 #endif
       
   208     return QString("Default");
       
   209 }
       
   210 
       
   211 void S60AudioPlayerSession::setActiveEndpoint(const QString& name)
       
   212 {
       
   213     CAudioOutput::TAudioOutputPreference output = CAudioOutput::ENoPreference;
       
   214 
       
   215     if (name == QString("Default"))
       
   216         output = CAudioOutput::ENoPreference;
       
   217     else if (name == QString("All"))
       
   218         output = CAudioOutput::EAll;
       
   219     else if (name == QString("None"))
       
   220         output = CAudioOutput::ENoOutput;
       
   221     else if (name == QString("Earphone"))
       
   222         output = CAudioOutput::EPrivate;
       
   223     else if (name == QString("Speaker"))
       
   224         output = CAudioOutput::EPublic;
       
   225 #ifndef HAS_NO_AUDIOROUTING
       
   226     if (m_audioOutput) {
       
   227         TRAPD(err, m_audioOutput->SetAudioOutputL(output));
       
   228         setError(err);
       
   229     }
       
   230 #endif
       
   231 
       
   232 }
       
   233 
       
   234 void S60AudioPlayerSession::DefaultAudioOutputChanged(CAudioOutput& aAudioOutput,
       
   235                                         CAudioOutput::TAudioOutputPreference aNewDefault)
       
   236 {
       
   237 #ifndef HAS_NO_AUDIOROUTING
       
   238     if (m_audioOutput) {
       
   239         CAudioOutput::TAudioOutputPreference output = m_audioOutput->AudioOutput();
       
   240         if (output == CAudioOutput::ENoPreference) {
       
   241             QString name;
       
   242             if (output == CAudioOutput::EAll)
       
   243                 name = QString("All");
       
   244             else if (output == CAudioOutput::ENoOutput)
       
   245                 name = QString("None");
       
   246             else if (output == CAudioOutput::EPrivate)
       
   247                 name = QString("Earphone");
       
   248             else if (output == CAudioOutput::EPublic)
       
   249                 name = QString("Speaker");
       
   250             if (!name.isEmpty())
       
   251                 emit activeEndpointChanged(name);
       
   252         }
       
   253     }
       
   254 #else
       
   255     Q_UNUSED(aAudioOutput)
       
   256     Q_UNUSED(aNewDefault)
       
   257 #endif
       
   258 }
       
   259 
       
   260 QString S60AudioPlayerSession::qStringFromTAudioOutputPreference(CAudioOutput::TAudioOutputPreference output) const
       
   261 {
       
   262     if (output == CAudioOutput::ENoPreference)
       
   263         return QString("Default");
       
   264     else if (output == CAudioOutput::EAll)
       
   265         return QString("All");
       
   266     else if (output == CAudioOutput::ENoOutput)
       
   267             return QString("None");
       
   268     else if (output == CAudioOutput::EPrivate)
       
   269             return QString("Earphone");
       
   270     else if (output == CAudioOutput::EPublic)
       
   271             return QString("Speaker");
       
   272     return QString();
       
   273 }