S60MMFLabUtility.cpp
上传用户:laixiong
上传日期:2007-03-11
资源大小:2994k
文件大小:5k
源码类别:

Symbian

开发平台:

C/C++

  1. // Copyright (c) 2006 Nokia Corporation.
  2. #include "S60MMFLabUtility.h"
  3. #include "s60mmflab.hrh"
  4. #include <MdaAudioTonePlayer.h>
  5. #include <eikmenup.h>
  6. #include <aknnotewrappers.h>
  7. // TONE UTILITY
  8. _LIT(KToneLabel, "Tone Utility...");
  9. CS60MMFLabToneUtility::CS60MMFLabToneUtility()
  10.     : iToneUtility(NULL)
  11.     {
  12.     // Do nothing
  13.     }
  14. CS60MMFLabToneUtility* CS60MMFLabToneUtility::NewL()
  15.     {
  16.     CS60MMFLabToneUtility* self = NewLC();
  17.     CleanupStack::Pop(self);  
  18.     return self;
  19.     }
  20. CS60MMFLabToneUtility* CS60MMFLabToneUtility::NewLC()
  21.     {
  22.     CS60MMFLabToneUtility* self = new (ELeave) CS60MMFLabToneUtility();
  23.     CleanupStack::PushL(self);
  24.     self->ConstructL();
  25.     return self;
  26.     }
  27. void CS60MMFLabToneUtility::ConstructL()
  28.     {
  29.     const TInt KFrequency = 1000; // Hz
  30.     const TTimeIntervalMicroSeconds KDuration =
  31.         TTimeIntervalMicroSeconds(6000000); // 6 seconds
  32.     
  33.     iToneUtility = CMdaAudioToneUtility::NewL(*this);
  34. iToneUtility->PrepareToPlayTone(KFrequency, KDuration);
  35.     }
  36. CS60MMFLabToneUtility::~CS60MMFLabToneUtility()
  37.     {
  38.     delete iToneUtility;
  39.     }
  40. void CS60MMFLabToneUtility::MatoPrepareComplete(TInt aError)
  41. {
  42. _LIT(KWarningNote, "The tone utility could not be configured");
  43.     if (aError == KErrNone)
  44.         {
  45.         TInt vol = iToneUtility->MaxVolume()/2;
  46.         iToneUtility->SetVolume(vol);
  47.         }
  48.     else
  49.         {
  50.         CAknWarningNote* warnNote = new (ELeave) CAknWarningNote;
  51.         warnNote->ExecuteLD( KWarningNote );
  52.         }
  53. }
  54. void CS60MMFLabToneUtility::MatoPlayComplete(TInt aError)
  55. {
  56. _LIT(KWarningNote, "The tone could not be played");
  57. if (aError != KErrNone)
  58.         {
  59.         CAknWarningNote* warnNote = new (ELeave) CAknWarningNote;
  60.         warnNote->ExecuteLD( KWarningNote );
  61.         }
  62. }
  63. const TDesC& CS60MMFLabToneUtility::GetLabel()
  64. {
  65.     return KToneLabel;
  66. }
  67. void CS60MMFLabToneUtility::Play()
  68.     {
  69.     iToneUtility->Play();
  70.     }
  71. void CS60MMFLabToneUtility::CancelPlay()
  72.     {
  73.     iToneUtility->CancelPlay();
  74.     }
  75. void CS60MMFLabToneUtility::SetOptionsMenuL(CEikMenuPane* aMenuPane)
  76.     {
  77.     TMdaAudioToneUtilityState state = iToneUtility->State();
  78.     
  79.     switch (state)
  80.         {
  81.         case EMdaAudioToneUtilityNotReady:
  82.          aMenuPane->SetItemDimmed(ES60MMFLabCmdAppPlay, ETrue);
  83.          aMenuPane->SetItemDimmed(ES60MMFLabCmdAppStop, ETrue);
  84.          break;
  85.         
  86.     case EMdaAudioToneUtilityPrepared:
  87.         aMenuPane->SetItemDimmed(ES60MMFLabCmdAppStop, ETrue);
  88.         break;
  89.         
  90.     case EMdaAudioToneUtilityPlaying:
  91.         aMenuPane->SetItemDimmed(ES60MMFLabCmdAppChange, ETrue);
  92.         aMenuPane->SetItemDimmed(ES60MMFLabCmdAppPlay, ETrue);
  93.         break;
  94.         
  95.     default:
  96.         break;
  97.         }
  98.     }
  99. // AUDIO PLAYER UTILITY
  100. _LIT(KPlayerLabel, "Player Utility");
  101. _LIT(KPlayerFile, "C:\Data\audio_sample.amr");
  102. CS60MMFLabPlayerUtility::CS60MMFLabPlayerUtility()
  103. : iPlayerUtility(NULL), iState(EPlayerNotReady)
  104.     {
  105.     // Do nothing
  106.     }
  107. CS60MMFLabPlayerUtility* CS60MMFLabPlayerUtility::NewL()
  108.     {
  109.     CS60MMFLabPlayerUtility* self = NewLC();
  110.     CleanupStack::Pop(self);  
  111.     return self;
  112.     }
  113. CS60MMFLabPlayerUtility* CS60MMFLabPlayerUtility::NewLC()
  114.     {
  115.     CS60MMFLabPlayerUtility* self = new (ELeave) CS60MMFLabPlayerUtility();
  116.     CleanupStack::PushL(self);
  117.     self->ConstructL();
  118.     return self;
  119.     }
  120. void CS60MMFLabPlayerUtility::ConstructL()
  121.     {
  122.     iPlayerUtility =
  123.         CMdaAudioPlayerUtility::NewFilePlayerL(KPlayerFile, *this);
  124.     }
  125. CS60MMFLabPlayerUtility::~CS60MMFLabPlayerUtility()
  126.     {
  127.     delete iPlayerUtility;
  128.     }
  129. void CS60MMFLabPlayerUtility::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& /*aDuration*/)
  130. {
  131. _LIT(KWarnNote, "The audio player utility could not be initialised");
  132.     switch(aError)
  133.         {
  134.         case KErrNone:
  135.             iState = EPlayerReady;
  136.             break;
  137.             
  138.         default:
  139.         {
  140.         CAknWarningNote* warnNote = new (ELeave) CAknWarningNote;
  141.         warnNote->ExecuteLD( KWarnNote );
  142.         break;
  143.         }
  144.         }
  145. }
  146. void CS60MMFLabPlayerUtility::MapcPlayComplete(TInt aError)
  147. {
  148. _LIT(KWarningNote, "The audio file could not be played");
  149. if (aError == KErrNone)
  150.         {
  151.         CAknWarningNote* warnNote = new (ELeave) CAknWarningNote;
  152.         warnNote->ExecuteLD( KWarningNote );
  153.         }
  154.         
  155.     iState = EPlayerReady;
  156. }
  157. const TDesC& CS60MMFLabPlayerUtility::GetLabel()
  158. {
  159.     return KPlayerLabel;
  160. }
  161. void CS60MMFLabPlayerUtility::Play()
  162.     {
  163.     iPlayerUtility->Play();
  164. iState = EPlayerPlaying;
  165.     }
  166. void CS60MMFLabPlayerUtility::Stop()
  167.     {
  168.     iPlayerUtility->Stop();
  169. iState = EPlayerReady;
  170.     }
  171. void CS60MMFLabPlayerUtility::SetOptionsMenuL(CEikMenuPane* aMenuPane)
  172.     {
  173.     switch (iState)
  174.         {
  175.     case EPlayerNotReady:
  176.      aMenuPane->SetItemDimmed(ES60MMFLabCmdAppPlay, ETrue);
  177.          aMenuPane->SetItemDimmed(ES60MMFLabCmdAppStop, ETrue);
  178.         break;
  179.         
  180.     case EPlayerReady:
  181.         aMenuPane->SetItemDimmed(ES60MMFLabCmdAppStop, ETrue);
  182.         break;
  183.         
  184.     case EPlayerPlaying:
  185.         aMenuPane->SetItemDimmed(ES60MMFLabCmdAppChange, ETrue);
  186.         aMenuPane->SetItemDimmed(ES60MMFLabCmdAppPlay, ETrue);
  187.         break;
  188.         
  189. default:
  190.         break;
  191.         }
  192.     }
  193.     
  194. // End of File