javauis/mmapi_qt/baseline/src.emc/cmmaemcaudioplayer.cpp
branchRCL_3
changeset 25 ae942d28ec0e
equal deleted inserted replaced
24:6c158198356e 25:ae942d28ec0e
       
     1 /*
       
     2 * Copyright (c) 2002-2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  This class is used for playing sounds
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //  INCLUDE FILES
       
    20 #include <AudioPreference.h>
       
    21 #include <logger.h>
       
    22 #include "cmmaemcaudioplayer.h"
       
    23 
       
    24 CMMAEMCAudioPlayer* CMMAEMCAudioPlayer::NewLC(
       
    25     CMMAEMCResolver* aResolver)
       
    26 {
       
    27     CMMAEMCAudioPlayer* self = new(ELeave) CMMAEMCAudioPlayer(aResolver);
       
    28     CleanupStack::PushL(self);
       
    29     self->ConstructL();
       
    30     return self;
       
    31 }
       
    32 
       
    33 EXPORT_C CMMAEMCAudioPlayer::~CMMAEMCAudioPlayer()
       
    34 {
       
    35 }
       
    36 
       
    37 EXPORT_C CMMAEMCAudioPlayer::CMMAEMCAudioPlayer(
       
    38     CMMAEMCResolver* aResolver):
       
    39         CMMAEMCPlayerBase(aResolver)
       
    40 {
       
    41     LOG(EJavaMMAPI, EInfo, "MMA::CMMAEMCAudioPlayer::CMMAEMCAudioPlayer");
       
    42 }
       
    43 
       
    44 EXPORT_C void CMMAEMCAudioPlayer::ConstructL()
       
    45 {
       
    46     LOG(EJavaMMAPI, EInfo, "MMA::CMMAEMCAudioPlayer::ConstructL +");
       
    47     CMMAEMCPlayerBase::ConstructL();
       
    48     LOG(EJavaMMAPI, EInfo, "MMA::CMMAEMCAudioPlayer::ConstructL -");
       
    49 }
       
    50 
       
    51 EXPORT_C void CMMAEMCAudioPlayer::PrefetchDataL(const TDesC8& /*aData*/)
       
    52 {
       
    53     LOG(EJavaMMAPI, EInfo, "MMA::CMMAEMCAudioPlayer::PrefetchDataL +");
       
    54 
       
    55     User::LeaveIfError(iMStreamControl->Prime());
       
    56     LOG(EJavaMMAPI, EInfo, "MMA::CMMAEMCAudioPlayer::PrefetchDataL -");
       
    57 }
       
    58 
       
    59 EXPORT_C void CMMAEMCAudioPlayer::PrefetchFileL()
       
    60 {
       
    61     LOG(EJavaMMAPI, EInfo, "MMA::CMMAEMCAudioPlayer::Prefetching from file");
       
    62 }
       
    63 
       
    64 EXPORT_C void CMMAEMCAudioPlayer::PlayCompleteL(TInt aError)
       
    65 {
       
    66     LOG(EJavaMMAPI, EInfo, "MMA::CMMAEMCAudioPlayer::PlayCompleteL +");
       
    67     TInt64 time;
       
    68     GetDuration(&time);
       
    69     iMediaTime = time;
       
    70     iStartedEventTime = 0;
       
    71 
       
    72     ChangeState(EPrefetched);   // ready to play again
       
    73 
       
    74     // Send 'Stopped' only when stop() is called.
       
    75     PostLongEvent(CMMAPlayerEvent::EEndOfMedia, time);
       
    76 
       
    77     if (aError == KErrNone)
       
    78     {
       
    79         iRepeatCount++;
       
    80 
       
    81         // priming again for allowing e.g. media time setting
       
    82         User::LeaveIfError(iMStreamControl->Prime());
       
    83 
       
    84         if (iRepeatForever || iRepeatCount < iRepeatNumberOfTimes)
       
    85         {
       
    86             StartL();
       
    87         }
       
    88         else
       
    89         {
       
    90             iRepeatCount = 0;
       
    91 
       
    92             TInt64 position(0);
       
    93             User::LeaveIfError(iMStreamControl->SetPosition(position));
       
    94         }
       
    95     }
       
    96     else
       
    97     {
       
    98         // error has occured, setting correct number of
       
    99         // repeats for next start
       
   100         SetLoopCount(iRepeatNumberOfTimes);
       
   101     }
       
   102     LOG(EJavaMMAPI, EInfo, "MMA::CMMAEMCAudioPlayer::PlayCompleteL -");
       
   103 }
       
   104 
       
   105 EXPORT_C void CMMAEMCAudioPlayer::RealizeL()
       
   106 {
       
   107     LOG(EJavaMMAPI, EInfo, "CMMAEMCAudioPlayer::RealizeL +");
       
   108     // DataSource must have at least 1 stream or
       
   109     // we must have file to play
       
   110     if ((iSourceStreams.Count() == 0) && !iFileName)
       
   111     {
       
   112         LOG(EJavaMMAPI, EInfo, "CMMAEMCAudioPlayer::RealizeL : Not Enough Streams");
       
   113         User::Leave(KErrNotEnoughStreams);
       
   114     }
       
   115     User::LeaveIfError(iMStreamControl->Open());
       
   116 
       
   117     if (!iActiveSchedulerWait->IsStarted())
       
   118     {
       
   119         iActiveSchedulerWait->Start();
       
   120     }
       
   121     CMMAPlayer::RealizeL();
       
   122     LOG(EJavaMMAPI, EInfo, "CMMAEMCAudioPlayer::RealizeL -");
       
   123 }
       
   124 
       
   125 EXPORT_C void CMMAEMCAudioPlayer::PrefetchL()
       
   126 {
       
   127     LOG(EJavaMMAPI, EInfo, "CMMAEMCAudioPlayer::PrefetchL +");
       
   128     __ASSERT_DEBUG((iSourceStreams.Count() > 0) || iFileName, User::Invariant());
       
   129 
       
   130     if (iFileName)
       
   131     {
       
   132         // prefetching the file
       
   133         PrefetchFileL();
       
   134         // we can go to prefetched state immediately
       
   135         ChangeState(EPrefetched);
       
   136         PostActionCompleted(KErrNone);
       
   137     }
       
   138     else
       
   139     {
       
   140         // Using TDes -- load the whole sound
       
   141         iSourceStreams[ 0 ]->ReadAllL();
       
   142     }
       
   143     // CMMASourceStream will notify with ReadCompleted
       
   144     LOG(EJavaMMAPI, EInfo, "CMMAEMCAudioPlayer::PrefetchL -");
       
   145 }
       
   146 
       
   147 EXPORT_C const TDesC& CMMAEMCAudioPlayer::Type()
       
   148 {
       
   149     // Should be used in AMMS Implementation to differentiate between
       
   150     // this new kind of player with others
       
   151     return KMMAEMCAudioPlayer;
       
   152 }
       
   153 
       
   154 //
       
   155 // CMMASourceStreamReader finished read operation
       
   156 // This is called when ReadL is completed in Prefetch()
       
   157 //
       
   158 EXPORT_C void CMMAEMCAudioPlayer::ReadCompletedL(TInt aStatus, const TDesC8& aData)
       
   159 {
       
   160     LOG(EJavaMMAPI, EInfo, "CMMAEMCAudioPlayer::ReadCompletedL +");
       
   161     LOG1(EJavaMMAPI, EInfo, "CMMAEMCAudioPlayer::ReadCompletedL: status = %d", aStatus);
       
   162     if (aStatus < KErrNone)
       
   163     {
       
   164         PostActionCompleted(aStatus);
       
   165     }
       
   166     else
       
   167     {
       
   168         TRAPD(err, PrefetchDataL(aData));
       
   169         if (err == KErrNone)
       
   170         {
       
   171             ChangeState(EPrefetched);
       
   172         }
       
   173         PostActionCompleted(err);
       
   174     }
       
   175     LOG(EJavaMMAPI, EInfo, "CMMAEMCAudioPlayer::ReadCompletedL -");
       
   176 }
       
   177 
       
   178 //  END OF FILE