S60MMFLabUtility.cpp
上传用户:laixiong
上传日期:2007-03-11
资源大小:2994k
文件大小:5k
- // Copyright (c) 2006 Nokia Corporation.
- #include "S60MMFLabUtility.h"
- #include "s60mmflab.hrh"
- #include <MdaAudioTonePlayer.h>
- #include <eikmenup.h>
- #include <aknnotewrappers.h>
- // TONE UTILITY
- _LIT(KToneLabel, "Tone Utility...");
- CS60MMFLabToneUtility::CS60MMFLabToneUtility()
- : iToneUtility(NULL)
- {
- // Do nothing
- }
- CS60MMFLabToneUtility* CS60MMFLabToneUtility::NewL()
- {
- CS60MMFLabToneUtility* self = NewLC();
- CleanupStack::Pop(self);
- return self;
- }
- CS60MMFLabToneUtility* CS60MMFLabToneUtility::NewLC()
- {
- CS60MMFLabToneUtility* self = new (ELeave) CS60MMFLabToneUtility();
- CleanupStack::PushL(self);
- self->ConstructL();
- return self;
- }
- void CS60MMFLabToneUtility::ConstructL()
- {
- const TInt KFrequency = 1000; // Hz
- const TTimeIntervalMicroSeconds KDuration =
- TTimeIntervalMicroSeconds(6000000); // 6 seconds
-
- iToneUtility = CMdaAudioToneUtility::NewL(*this);
- iToneUtility->PrepareToPlayTone(KFrequency, KDuration);
- }
- CS60MMFLabToneUtility::~CS60MMFLabToneUtility()
- {
- delete iToneUtility;
- }
- void CS60MMFLabToneUtility::MatoPrepareComplete(TInt aError)
- {
- _LIT(KWarningNote, "The tone utility could not be configured");
- if (aError == KErrNone)
- {
- TInt vol = iToneUtility->MaxVolume()/2;
- iToneUtility->SetVolume(vol);
- }
- else
- {
- CAknWarningNote* warnNote = new (ELeave) CAknWarningNote;
- warnNote->ExecuteLD( KWarningNote );
- }
- }
- void CS60MMFLabToneUtility::MatoPlayComplete(TInt aError)
- {
- _LIT(KWarningNote, "The tone could not be played");
-
- if (aError != KErrNone)
- {
- CAknWarningNote* warnNote = new (ELeave) CAknWarningNote;
- warnNote->ExecuteLD( KWarningNote );
- }
- }
- const TDesC& CS60MMFLabToneUtility::GetLabel()
- {
- return KToneLabel;
- }
- void CS60MMFLabToneUtility::Play()
- {
- iToneUtility->Play();
- }
- void CS60MMFLabToneUtility::CancelPlay()
- {
- iToneUtility->CancelPlay();
- }
- void CS60MMFLabToneUtility::SetOptionsMenuL(CEikMenuPane* aMenuPane)
- {
- TMdaAudioToneUtilityState state = iToneUtility->State();
-
- switch (state)
- {
- case EMdaAudioToneUtilityNotReady:
- aMenuPane->SetItemDimmed(ES60MMFLabCmdAppPlay, ETrue);
- aMenuPane->SetItemDimmed(ES60MMFLabCmdAppStop, ETrue);
- break;
-
- case EMdaAudioToneUtilityPrepared:
- aMenuPane->SetItemDimmed(ES60MMFLabCmdAppStop, ETrue);
- break;
-
- case EMdaAudioToneUtilityPlaying:
- aMenuPane->SetItemDimmed(ES60MMFLabCmdAppChange, ETrue);
- aMenuPane->SetItemDimmed(ES60MMFLabCmdAppPlay, ETrue);
- break;
-
- default:
- break;
- }
- }
- // AUDIO PLAYER UTILITY
- _LIT(KPlayerLabel, "Player Utility");
- _LIT(KPlayerFile, "C:\Data\audio_sample.amr");
- CS60MMFLabPlayerUtility::CS60MMFLabPlayerUtility()
- : iPlayerUtility(NULL), iState(EPlayerNotReady)
- {
- // Do nothing
- }
- CS60MMFLabPlayerUtility* CS60MMFLabPlayerUtility::NewL()
- {
- CS60MMFLabPlayerUtility* self = NewLC();
- CleanupStack::Pop(self);
- return self;
- }
- CS60MMFLabPlayerUtility* CS60MMFLabPlayerUtility::NewLC()
- {
- CS60MMFLabPlayerUtility* self = new (ELeave) CS60MMFLabPlayerUtility();
- CleanupStack::PushL(self);
- self->ConstructL();
- return self;
- }
- void CS60MMFLabPlayerUtility::ConstructL()
- {
- iPlayerUtility =
- CMdaAudioPlayerUtility::NewFilePlayerL(KPlayerFile, *this);
- }
- CS60MMFLabPlayerUtility::~CS60MMFLabPlayerUtility()
- {
- delete iPlayerUtility;
- }
- void CS60MMFLabPlayerUtility::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& /*aDuration*/)
- {
- _LIT(KWarnNote, "The audio player utility could not be initialised");
- switch(aError)
- {
- case KErrNone:
- iState = EPlayerReady;
- break;
-
- default:
- {
- CAknWarningNote* warnNote = new (ELeave) CAknWarningNote;
- warnNote->ExecuteLD( KWarnNote );
- break;
- }
- }
- }
- void CS60MMFLabPlayerUtility::MapcPlayComplete(TInt aError)
- {
- _LIT(KWarningNote, "The audio file could not be played");
-
- if (aError == KErrNone)
- {
- CAknWarningNote* warnNote = new (ELeave) CAknWarningNote;
- warnNote->ExecuteLD( KWarningNote );
- }
-
- iState = EPlayerReady;
- }
- const TDesC& CS60MMFLabPlayerUtility::GetLabel()
- {
- return KPlayerLabel;
- }
- void CS60MMFLabPlayerUtility::Play()
- {
- iPlayerUtility->Play();
- iState = EPlayerPlaying;
- }
- void CS60MMFLabPlayerUtility::Stop()
- {
- iPlayerUtility->Stop();
- iState = EPlayerReady;
- }
- void CS60MMFLabPlayerUtility::SetOptionsMenuL(CEikMenuPane* aMenuPane)
- {
- switch (iState)
- {
- case EPlayerNotReady:
- aMenuPane->SetItemDimmed(ES60MMFLabCmdAppPlay, ETrue);
- aMenuPane->SetItemDimmed(ES60MMFLabCmdAppStop, ETrue);
- break;
-
- case EPlayerReady:
- aMenuPane->SetItemDimmed(ES60MMFLabCmdAppStop, ETrue);
- break;
-
- case EPlayerPlaying:
- aMenuPane->SetItemDimmed(ES60MMFLabCmdAppChange, ETrue);
- aMenuPane->SetItemDimmed(ES60MMFLabCmdAppPlay, ETrue);
- break;
-
- default:
- break;
- }
- }
-
- // End of File