examples/sfexamples/AudioPlaying/src/SimpleAudioPlayer.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:
00015 // 
00016 
00017 // INCLUDE FILES
00018 #include <eikenv.h>
00019 #include "SimpleAudioPlayer.h"
00020 
00021 // CONSTANTS
00022 const TInt KOneSecond = 1000 * 1000; // 1 second in microseconds
00023 const TInt KVolumeDenominator = 2;
00024 
00025 // METHODS DEFINITION
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         // Get the current position of the playback.
00082         TTimeIntervalMicroSeconds position;
00083         iPlayerUtility->GetPosition(position);
00084         
00085         // Add the interval to the current position.
00086         position = position.Int64() - aIntervalInSeconds * KOneSecond;
00087         
00088         // Set the new position.
00089         iPlayerUtility->SetPosition(position);
00090         iPlayerUtility->Play();
00091         }
00092 
00093 void CSimpleAudioPlayer::FastForward(TInt aIntervalInSeconds)
00094         {
00095         iPlayerUtility->Pause();
00096         
00097         // Get the current position of the playback.
00098         TTimeIntervalMicroSeconds position;
00099         iPlayerUtility->GetPosition(position);
00100         
00101         // Subtract the interval from the current position.
00102         position = position.Int64() + aIntervalInSeconds * KOneSecond;
00103         
00104         // Set the new position.
00105         iPlayerUtility->SetPosition(position);
00106         iPlayerUtility->Play();
00107         }
00108 
00109 void CSimpleAudioPlayer::MapcInitComplete(TInt aError,
00110                 const TTimeIntervalMicroSeconds& /*aDuration*/)
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                 // Do something when an error happens.
00123                 DisplayErrorMessage(aError);
00124                 }
00125         }
00126 
00127 void CSimpleAudioPlayer::MapcPlayComplete(TInt aError)
00128         {
00129         if (KErrNone == aError)
00130                 {
00131                 // Do something when the playback can be completed successfully.
00132                 }
00133         else
00134                 {
00135                 // Do something when an error happens.
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 // End of File

Generated by  doxygen 1.6.2