javauis/mmapi_akn/baseline/src/cmmaaudiovolumecontrol.cpp
branchRCL_3
changeset 14 04becd199f91
equal deleted inserted replaced
13:f5050f1da672 14:04becd199f91
       
     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 <jdebug.h>
       
    20 #include "cmmaaudiovolumecontrol.h"
       
    21 #include "cmmaaudioplayer.h"
       
    22 
       
    23 
       
    24 CMMAAudioVolumeControl::CMMAAudioVolumeControl(CMMAAudioPlayer* aPlayer)
       
    25         : CMMAVolumeControl(aPlayer),
       
    26         iAudioPlayDeviceCommands(aPlayer->Controller())
       
    27 {
       
    28 }
       
    29 
       
    30 void CMMAAudioVolumeControl::ConstructL()
       
    31 {
       
    32     ConstructBaseL();
       
    33 }
       
    34 
       
    35 EXPORT_C CMMAAudioVolumeControl* CMMAAudioVolumeControl::NewL(CMMAAudioPlayer* aPlayer)
       
    36 {
       
    37     CMMAAudioVolumeControl* self = new(ELeave)CMMAAudioVolumeControl(aPlayer);
       
    38     CleanupStack::PushL(self);
       
    39     self->ConstructL();
       
    40     CleanupStack::Pop();
       
    41     return self;
       
    42 }
       
    43 
       
    44 
       
    45 void CMMAAudioVolumeControl::DoSetLevelL(TInt aLevel)
       
    46 {
       
    47     TInt maxVolume = 0;
       
    48     User::LeaveIfError(iAudioPlayDeviceCommands.GetMaxVolume(maxVolume));
       
    49     // aLevel is the desired volume in range 0..100
       
    50     User::LeaveIfError(iAudioPlayDeviceCommands.SetVolume(
       
    51                            aLevel * maxVolume / KMMAVolumeMaxLevel));
       
    52 }
       
    53 
       
    54 TInt CMMAAudioVolumeControl::DoGetLevelL()
       
    55 {
       
    56     TInt maxVolume = 0;
       
    57     User::LeaveIfError(iAudioPlayDeviceCommands.GetMaxVolume(maxVolume));
       
    58     __ASSERT_DEBUG(maxVolume != 0, User::Invariant());
       
    59     TInt volume = 0;
       
    60     User::LeaveIfError(iAudioPlayDeviceCommands.GetVolume(volume));
       
    61     // result is in range 0..100
       
    62     return (volume * KMMAVolumeMaxLevel / maxVolume);
       
    63 }
       
    64 
       
    65 //  END OF FILE