qtmobility/plugins/multimedia/symbian/mediaplayer/s60audioplayersession.cpp
changeset 4 90517678cc4f
parent 1 2b40d63a9c3d
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 S60AudioPlayerSession::S60AudioPlayerSession(QObject *parent)
       
    47     : S60MediaPlayerSession(parent)
       
    48 {    
       
    49     QT_TRAP_THROWING(m_player = CAudioPlayer::NewL(*this, 0, EMdaPriorityPreferenceNone));
       
    50     
       
    51 #if defined(S60_DRM_SUPPORTED) && defined(__S60_50__)
       
    52     m_player->RegisterForAudioLoadingNotification(*this);
       
    53 #endif   
       
    54 }
       
    55 
       
    56 S60AudioPlayerSession::~S60AudioPlayerSession()
       
    57 {
       
    58     m_player->Close();
       
    59     delete m_player;
       
    60 }
       
    61 
       
    62 void S60AudioPlayerSession::doLoadL(const TDesC &path)
       
    63 {
       
    64     m_player->OpenFileL(path);
       
    65 }
       
    66 
       
    67 int S60AudioPlayerSession::doGetDurationL() const
       
    68 {
       
    69     return m_player->Duration().Int64() / 1000;
       
    70 }
       
    71 
       
    72 qint64 S60AudioPlayerSession::doGetPositionL() const
       
    73 {
       
    74     TTimeIntervalMicroSeconds ms = 0;
       
    75     m_player->GetPosition(ms);
       
    76     return ms.Int64() / 1000;
       
    77 }
       
    78 
       
    79 bool S60AudioPlayerSession::isVideoAvailable() const
       
    80 {
       
    81     return false;
       
    82 }
       
    83 bool S60AudioPlayerSession::isAudioAvailable() const
       
    84 {
       
    85     return true; // this is a bit happy scenario, but we do emit error that we can't play
       
    86 }
       
    87 void S60AudioPlayerSession::doPlay()
       
    88 {
       
    89     m_player->Play();
       
    90 }
       
    91 
       
    92 void S60AudioPlayerSession::doPauseL()
       
    93 {
       
    94     m_player->Pause();
       
    95 }
       
    96 
       
    97 void S60AudioPlayerSession::doStop()
       
    98 {
       
    99     m_player->Stop();
       
   100 }
       
   101 
       
   102 void S60AudioPlayerSession::doSetVolumeL(int volume)
       
   103 {    
       
   104     m_player->SetVolume((volume / 100.0) * m_player->MaxVolume());
       
   105 }
       
   106 
       
   107 void S60AudioPlayerSession::doSetPositionL(qint64 microSeconds)
       
   108 {   
       
   109     m_player->SetPosition(TTimeIntervalMicroSeconds(microSeconds));
       
   110 }
       
   111 
       
   112 void S60AudioPlayerSession::updateMetaDataEntriesL()
       
   113 {
       
   114     metaDataEntries().clear();
       
   115     int numberOfMetaDataEntries = 0;
       
   116     
       
   117     m_player->GetNumberOfMetaDataEntries(numberOfMetaDataEntries);
       
   118     
       
   119     for (int i = 0; i < numberOfMetaDataEntries; i++) {
       
   120         CMMFMetaDataEntry *entry = NULL;
       
   121         entry = m_player->GetMetaDataEntryL(i);
       
   122         metaDataEntries().insert(QString::fromUtf16(entry->Name().Ptr(), entry->Name().Length()), QString::fromUtf16(entry->Value().Ptr(), entry->Value().Length()));
       
   123         delete entry;
       
   124     }
       
   125     emit metaDataChanged();
       
   126 }
       
   127 
       
   128 #ifdef S60_DRM_SUPPORTED   
       
   129 void S60AudioPlayerSession::MdapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& aDuration)
       
   130 #else 
       
   131 void S60AudioPlayerSession::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& aDuration)
       
   132 #endif
       
   133 {
       
   134     Q_UNUSED(aDuration);
       
   135     setError(aError);
       
   136     initComplete();
       
   137 }
       
   138 
       
   139 #ifdef S60_DRM_SUPPORTED   
       
   140 void S60AudioPlayerSession::MdapcPlayComplete(TInt aError)
       
   141 #else
       
   142 void S60AudioPlayerSession::MapcPlayComplete(TInt aError)
       
   143 #endif
       
   144 {
       
   145     setError(aError);
       
   146     playComplete();
       
   147 }