examples/sfexamples/AudioTone/src/AudioTonePlayer.cpp

00001 // 
00002 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
00003 // All rights reserved.
00004 // This component and the accompanying materials are made available
00005 // under the terms of the License "Eclipse Public License v1.0"
00006 // which accompanies this distribution, and is available
00007 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
00008 // 
00009 // Initial Contributors:
00010 // Nokia Corporation - initial contribution.
00011 // 
00012 // Contributors:
00013 // 
00014 // Description:  CAudioTonePlayer implementation
00015 // 
00016 // 
00017 
00018 
00019 // INCLUDE FILES
00020 #include <eikenv.h>
00021 #include "AudioTonePlayer.h"
00022 
00023 // CONSTANTS
00024 const TInt KVolumeDenominator = 2;
00025 
00026 // METHODS DEFINITION
00027 
00028 CAudioTonePlayer::CAudioTonePlayer()
00029         {
00030         }
00031 
00032 CAudioTonePlayer::~CAudioTonePlayer()
00033         {
00034         delete iTonePlayer;
00035         }
00036 
00037 CAudioTonePlayer* CAudioTonePlayer::NewLC()
00038         {
00039         CAudioTonePlayer* self = new (ELeave)CAudioTonePlayer();
00040         CleanupStack::PushL(self);
00041         self->ConstructL();
00042         return self;
00043         }
00044 
00045 CAudioTonePlayer* CAudioTonePlayer::NewL()
00046         {
00047         CAudioTonePlayer* self=CAudioTonePlayer::NewLC();
00048         CleanupStack::Pop(self);
00049         return self;
00050         }
00051 
00052 void CAudioTonePlayer::ConstructL()
00053         {
00054         iTonePlayer = CMdaAudioToneUtility::NewL(*this);
00055         }
00056 
00057 void CAudioTonePlayer::PlayTone(TInt aFrequency,
00058                 TTimeIntervalMicroSeconds aDuration)
00059         {
00060         Stop();
00061         iTonePlayer->PrepareToPlayTone(aFrequency, aDuration);
00062         }
00063 
00064 void CAudioTonePlayer::PlayDualTone(TInt aFrequency1, TInt aFrequency2,
00065                 TTimeIntervalMicroSeconds aDuration)
00066         {
00067         Stop();
00068         iTonePlayer->PrepareToPlayDualTone(aFrequency1, aFrequency2,
00069                         aDuration);
00070         }
00071 
00072 void CAudioTonePlayer::Stop()
00073         {
00074         iTonePlayer->CancelPlay();
00075         }
00076 
00077 void CAudioTonePlayer::MatoPrepareComplete(TInt aError)
00078         {
00079         if (KErrNone == aError)
00080                 {
00081                 iTonePlayer->SetVolume(iTonePlayer->MaxVolume()
00082                                 / KVolumeDenominator);
00083                 iTonePlayer->Play();
00084                 }
00085         else
00086                 {
00087                 // Do something when error happens.
00088                 DisplayErrorMessage(aError);
00089                 }
00090         }
00091 
00092 void CAudioTonePlayer::MatoPlayComplete(TInt aError)
00093         {
00094         if (KErrNone == aError)
00095                 {
00096                 }
00097         else
00098                 {
00099                 // Do something when error happens.
00100                 DisplayErrorMessage(aError);
00101                 }
00102         }
00103 
00104 void CAudioTonePlayer::DisplayErrorMessage(TInt aError)
00105         {
00106         const TInt KMaxBuffer = 15;
00107         _LIT(KErrorMessage, "Error: %d");
00108         TBuf<KMaxBuffer> buffer;
00109         buffer.AppendFormat(KErrorMessage, aError);
00110         TRAP_IGNORE(CEikonEnv::Static()->InfoWinL(KNullDesC, buffer));
00111         }
00112 
00113 // End of File

Generated by  doxygen 1.6.2