javauis/mmapi_akn/baseline/src/cmmammfratecontrol.cpp
branchRCL_3
changeset 26 2455ef1f5bbc
parent 14 04becd199f91
equal deleted inserted replaced
25:ae942d28ec0e 26:2455ef1f5bbc
       
     1 /*
       
     2 * Copyright (c) 2002 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 implements generic RateControl functionality.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //  INCLUDE FILES
       
    20 #include <jdebug.h>
       
    21 #include <e32base.h>
       
    22 
       
    23 #include "cmmammfratecontrol.h"
       
    24 
       
    25 namespace
       
    26 {
       
    27 const TInt KErrorMessageSize = 32;
       
    28 _LIT(KErrDefaultError, "Symbian OS Error: %d");
       
    29 }
       
    30 
       
    31 CMMAMMFRateControl* CMMAMMFRateControl::NewL(CMMAMMFPlayerBase* aPlayer)
       
    32 {
       
    33     CMMAMMFRateControl* self = new(ELeave) CMMAMMFRateControl(aPlayer);
       
    34     CleanupStack::PushL(self);
       
    35     self->ConstructL();
       
    36     CleanupStack::Pop();
       
    37     return self;
       
    38 }
       
    39 
       
    40 CMMAMMFRateControl::~CMMAMMFRateControl()
       
    41 {
       
    42     DEBUG("MMA:CMMAMMFRateControl::~CMMAMMFRateControl");
       
    43 }
       
    44 
       
    45 CMMAMMFRateControl::CMMAMMFRateControl(CMMAMMFPlayerBase* aPlayer) :
       
    46         iPlayer(aPlayer), iCurrentRate(KMMADefaultRate)
       
    47 {
       
    48     DEBUG("MMA:CMMAMMFRateControl::CMMAMMFRateControl");
       
    49 }
       
    50 
       
    51 void CMMAMMFRateControl::ConstructL()
       
    52 {
       
    53     iPlayer->AddStateListenerL(this);
       
    54 }
       
    55 
       
    56 void CMMAMMFRateControl::StateChanged(TInt aState)
       
    57 {
       
    58     DEBUG("MMA:CMMAMMFRateControl::StateChanged");
       
    59     if (aState == CMMAPlayer::EStarted && iCurrentRate == KMMAMinRate)
       
    60     {
       
    61         RMMFController& controller = iPlayer->Controller();
       
    62         TInt err = controller.Pause();
       
    63         if ((err != KErrNone) && (err != KErrNotReady))
       
    64         {
       
    65             DEBUG_INT("CMMAMMFRateControl::StateChanged: Pause error %d", err);
       
    66             TBuf<KErrorMessageSize> errorMessage;
       
    67             errorMessage.Format(KErrDefaultError, err);
       
    68             iPlayer->PostStringEvent(CMMAPlayerEvent::EError, errorMessage);
       
    69         }
       
    70     }
       
    71 }
       
    72 
       
    73 TInt CMMAMMFRateControl::SetRateL(TInt aRate)
       
    74 {
       
    75     DEBUG("MMA:CMMAMMFRateControl::SetRateL");
       
    76     RMMFController& controller = iPlayer->Controller();
       
    77 
       
    78     TInt newRate;
       
    79     if (aRate <= KMMAMinRate)
       
    80     {
       
    81         newRate = KMMAMinRate;
       
    82     }
       
    83     else
       
    84     {
       
    85         newRate = KMMADefaultRate;
       
    86     }
       
    87 
       
    88     if ((iPlayer->State() == CMMAPlayer::EStarted) &&
       
    89             (newRate != iCurrentRate))
       
    90     {
       
    91         if (newRate == KMMAMinRate)
       
    92         {
       
    93             TInt err = controller.Pause();
       
    94             if ((err != KErrNone) && (err != KErrNotReady))
       
    95             {
       
    96                 User::Leave(err);
       
    97             }
       
    98         }
       
    99         else
       
   100         {
       
   101             User::LeaveIfError(controller.Play());
       
   102         }
       
   103     }
       
   104     iCurrentRate = newRate;
       
   105     return iCurrentRate;
       
   106 }
       
   107 
       
   108 TInt CMMAMMFRateControl::RateL()
       
   109 {
       
   110     return iCurrentRate;
       
   111 }
       
   112 
       
   113 
       
   114 //  END OF FILE