00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <eikenv.h>
00019 #include "SimpleAudioPlayer.h"
00020
00021
00022 const TInt KOneSecond = 1000 * 1000;
00023 const TInt KVolumeDenominator = 2;
00024
00025
00026
00027 CSimpleAudioPlayer::CSimpleAudioPlayer()
00028 {
00029 }
00030
00031 CSimpleAudioPlayer::~CSimpleAudioPlayer()
00032 {
00033 delete iPlayerUtility;
00034 }
00035
00036 CSimpleAudioPlayer* CSimpleAudioPlayer::NewLC()
00037 {
00038 CSimpleAudioPlayer* self = new (ELeave) CSimpleAudioPlayer();
00039 CleanupStack::PushL(self);
00040 self->ConstructL();
00041 return self;
00042 }
00043
00044 CSimpleAudioPlayer* CSimpleAudioPlayer::NewL()
00045 {
00046 CSimpleAudioPlayer* self = CSimpleAudioPlayer::NewLC();
00047 CleanupStack::Pop(self);
00048 return self;
00049 }
00050
00051 void CSimpleAudioPlayer::ConstructL()
00052 {
00053 iPlayerUtility = CMdaAudioPlayerUtility::NewL(*this);
00054 }
00055
00056 void CSimpleAudioPlayer::PlayL(const TDesC& aFileName)
00057 {
00058 iPlayerUtility->Close();
00059 iPlayerUtility->OpenFileL(aFileName);
00060 }
00061
00062 void CSimpleAudioPlayer::Pause()
00063 {
00064 iPlayerUtility->Pause();
00065 }
00066
00067 void CSimpleAudioPlayer::Resume()
00068 {
00069 iPlayerUtility->Play();
00070 }
00071
00072 void CSimpleAudioPlayer::Stop()
00073 {
00074 iPlayerUtility->Stop();
00075 }
00076
00077 void CSimpleAudioPlayer::Rewind(TInt aIntervalInSeconds)
00078 {
00079 iPlayerUtility->Pause();
00080
00081
00082 TTimeIntervalMicroSeconds position;
00083 iPlayerUtility->GetPosition(position);
00084
00085
00086 position = position.Int64() - aIntervalInSeconds * KOneSecond;
00087
00088
00089 iPlayerUtility->SetPosition(position);
00090 iPlayerUtility->Play();
00091 }
00092
00093 void CSimpleAudioPlayer::FastForward(TInt aIntervalInSeconds)
00094 {
00095 iPlayerUtility->Pause();
00096
00097
00098 TTimeIntervalMicroSeconds position;
00099 iPlayerUtility->GetPosition(position);
00100
00101
00102 position = position.Int64() + aIntervalInSeconds * KOneSecond;
00103
00104
00105 iPlayerUtility->SetPosition(position);
00106 iPlayerUtility->Play();
00107 }
00108
00109 void CSimpleAudioPlayer::MapcInitComplete(TInt aError,
00110 const TTimeIntervalMicroSeconds& )
00111 {
00112 if (KErrNone == aError)
00113 {
00114 iPlayerUtility->SetVolume(
00115 iPlayerUtility->MaxVolume() / KVolumeDenominator);
00116 iPlayerUtility->Play();
00117 }
00118 else
00119 {
00120 iPlayerUtility->Close();
00121
00122
00123 DisplayErrorMessage(aError);
00124 }
00125 }
00126
00127 void CSimpleAudioPlayer::MapcPlayComplete(TInt aError)
00128 {
00129 if (KErrNone == aError)
00130 {
00131
00132 }
00133 else
00134 {
00135
00136 DisplayErrorMessage(aError);
00137 }
00138 }
00139
00140 void CSimpleAudioPlayer::DisplayErrorMessage(TInt aError)
00141 {
00142 const TInt KMaxBuffer = 15;
00143 _LIT(KErrorMessage, "Error: %d");
00144 TBuf<KMaxBuffer> buffer;
00145 buffer.AppendFormat(KErrorMessage, aError);
00146 TRAP_IGNORE(CEikonEnv::Static()->InfoWinL(KNullDesC, buffer));
00147 }
00148
00149