javauis/mmapi_qt/baseline/src.emc/cmmaemcaudiovolumecontrol.cpp
changeset 23 98ccebc37403
equal deleted inserted replaced
21:2a9601315dfc 23:98ccebc37403
       
     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 setting volume to audio player
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <logger.h>
       
    20 #include "StreamControl.h"
       
    21 #include "EffectControl.h"
       
    22 #include "MMControlFactory.h"
       
    23 #include "cmmaemcaudiovolumecontrol.h"
       
    24 #include "cmmaemcaudioplayer.h"
       
    25 
       
    26 using multimedia ::KVolumeEffectControl;
       
    27 using multimedia ::MStreamControl;
       
    28 using multimedia ::MEffectControl;
       
    29 using multimedia ::CMultimediaFactory;
       
    30 
       
    31 EXPORT_C CMMAEMCAudioVolumeControl* CMMAEMCAudioVolumeControl::NewL(CMMAEMCAudioPlayer& aPlayer)
       
    32 {
       
    33     CMMAEMCAudioVolumeControl* self = new(ELeave)CMMAEMCAudioVolumeControl(aPlayer);
       
    34     CleanupStack::PushL(self);
       
    35     self->ConstructL();
       
    36     CleanupStack::Pop(self);
       
    37     return self;
       
    38 }
       
    39 
       
    40 EXPORT_C CMMAEMCAudioVolumeControl::CMMAEMCAudioVolumeControl(CMMAEMCAudioPlayer& aPlayer)
       
    41         : CMMAVolumeControl(&aPlayer), iPlayer(aPlayer)
       
    42 {
       
    43 }
       
    44 
       
    45 void CMMAEMCAudioVolumeControl::ConstructL()
       
    46 {
       
    47     ConstructBaseL();
       
    48     MStreamControl* streamControl = iPlayer.StreamControl();
       
    49     CMultimediaFactory* mmFactory = iPlayer.MMFactory();
       
    50 
       
    51     MEffectControl* temp(NULL);
       
    52     User::LeaveIfError(mmFactory->CreateEffectControl(KVolumeEffectControl, temp));
       
    53     iVolCntrl = static_cast<MVolumeControl*>(temp);
       
    54     User::LeaveIfError(streamControl->AddEffect(*iVolCntrl));
       
    55 }
       
    56 
       
    57 CMMAEMCAudioVolumeControl::~CMMAEMCAudioVolumeControl()
       
    58 {
       
    59     MStreamControl* streamControl = iPlayer.StreamControl();
       
    60     CMultimediaFactory* mmFactory = iPlayer.MMFactory();
       
    61 
       
    62     if ((NULL != streamControl) && (NULL != iVolCntrl))
       
    63     {
       
    64         streamControl->RemoveEffect(*iVolCntrl);
       
    65     }
       
    66 
       
    67     MEffectControl* temp = static_cast<MEffectControl*>(iVolCntrl);
       
    68 
       
    69     if (NULL != mmFactory)
       
    70     {
       
    71         mmFactory->DeleteEffectControl(temp);
       
    72     }
       
    73 }
       
    74 
       
    75 EXPORT_C void CMMAEMCAudioVolumeControl::DoSetLevelL(TInt aLevel)
       
    76 {
       
    77     TInt maxVolume = 0;
       
    78     User::LeaveIfError(iVolCntrl->GetMaxVolume(maxVolume));
       
    79     // aLevel is the desired volume in range 0..100
       
    80     TInt volLevel = aLevel * maxVolume / KMMAVolumeMaxLevel;
       
    81     User::LeaveIfError(iVolCntrl->SetVolume(volLevel));
       
    82     User::LeaveIfError(iVolCntrl->Apply());
       
    83 }
       
    84 
       
    85 EXPORT_C TInt CMMAEMCAudioVolumeControl::DoGetLevelL()
       
    86 {
       
    87     TInt maxVolume = 0;
       
    88     User::LeaveIfError(iVolCntrl->GetMaxVolume(maxVolume));
       
    89     __ASSERT_DEBUG(maxVolume != 0, User::Invariant());
       
    90     TInt volume = 0;
       
    91     User::LeaveIfError(iVolCntrl->GetVolume(volume));
       
    92     // result is in range 0..100
       
    93     return (volume * KMMAVolumeMaxLevel / maxVolume);
       
    94 }
       
    95 
       
    96 //  END OF FILE