//I have implemented the AMR playing functionalities in CAudioPlayerEngine class
//Declaration of required constants
//I hardcoded the amr file, you could use some file browser or you can get amr data from the descriptor array.
_LIT(KAmrFile, "\\system\\apps\\AudioPlayer\\test.amr");
//Cosntants needed for playing the amr file/descriptor
const TUid KMMFExControllerUID = {0x101F5022};
const TUid KMMFExDesFormatUID = {0x101FAF66};
const TUint32 KMMFFourCCCodeAMR = {0x524d4120};
void CAudioPlayerEngine::ConstructL()
{
//Declare "CMdaAudioRecorderUtility* iAmrPlayer" in the header file
iAmrPlayer = CMdaAudioRecorderUtility::NewL(*this,NULL,EMdaPriorityNormal,EMdaPriorityPreferenceTimeAndQuality);
}
void CAudioPlayerEngine::PlayAmrL()
{
/*
This method shows how amr file can be played from the descriptor. AMR file is
first read from the file to iStreamBuffer which is a TPtr8 to the descriptor data.
Then OpenDesL method is used to play the file.
*/
RFs fs;
CleanupClosePushL(fs); // PUSH
User::LeaveIfError(fs.Connect());
RFile file;
CleanupClosePushL(file); // PUSH
TFileName streamFile(KAmrFile);
User::LeaveIfError(CompleteWithAppPath(streamFile));
User::LeaveIfError(file.Open(fs, streamFile, EFileRead | EFileShareReadersOnly));
TInt fileSize = 0;
file.Size(fileSize);
//Declare in header file "TUint8* iSteamData"
iStreamData = new (ELeave) TUint8[fileSize];
//Declare in header file "TPtr8* iStreamBuffer"
iStreamBuffer = new (ELeave) TPtr8(iStreamData, fileSize, fileSize);
file.Read(*iStreamBuffer);
//OpenDesL method opens the amr stored in the descriptor buffer, as soon as the opening completes,
//MoscoStateChangeEvent(..) callback method is called
iAmrPlayer->OpenDesL(*iStreamBuffer,KMMFExControllerUID,KMMFExControllerUID,
KMMFExDesFormatUID,KMMFFourCCCodeAMR);
CleanupStack::PopAndDestroy(2);
/*
This is another method for playing amr file. amr file is directly played from the
file itself. In both cases CMdaAudioRecorderUtility class is used.
*/
/*
TFileName amrFile(KAmrFile);
User::LeaveIfError(CompleteWithAppPath(amrFile));
iAmrPlayer->OpenFileL(amrFile,KMMFExControllerUID,KMMFExControllerUID,
KMMFExDesFormatUID,KMMFFourCCCodeAMR);
*/
}
void CAudioPlayerEngine::MoscoStateChangeEvent(CBase* aObject, TInt aPreviousState, TInt aCurrentState, TInt aErrorCode)
{
//Checking the curren state. Current state has to be EOpen and aErrorCode has to be KErrNone.
if((aErrorCode == KErrNone) && (aCurrentState == iAmrPlayer->EOpen))
{
iState = EPlaying;
iAmrPlayer->PlayL();
}
}
//This is complete solution for handling AMR file, If someone having problem using this code, contact me.




