hi,
I am Trying to Implement Payer,( Not exactly Player)
In my app i am playing sound file which starts playing when i request Play n continue play repeatedly till i say stop playing on some condition....
My problem is some time Playing stops and some time Playing doesn't stop....
My implementation is as follows:
/*
* AudioPlayer.cpp
*
* Created on: Jan 19, 2012
* Author:
*/
#include "AudioPlayer.h"
#include <MdaAudioTonePlayer.h>
#include <eikmenup.h>
CPlayerUtility* CPlayerUtility::NewL(const TDesC& aFileName)
{
CPlayerUtility* self = NewLC(aFileName);
CleanupStack::Pop(self);
return self;
}
CPlayerUtility* CPlayerUtility::NewLC(const TDesC& aFileName)
{
CPlayerUtility* self = new (ELeave) CPlayerUtility();
CleanupStack::PushL(self);
self->ConstructL(aFileName);
return self;
}
CPlayerUtility::~CPlayerUtility()
{
generatePlaylog(_L("In Player delete IN FunctionL"));
if (iPlayUtility)
{
iPlayUtility->Stop();
iPlayUtility->Close();
}
delete iPlayUtility;
generatePlaylog(_L("In Player delete out FunctionL"));
}
CPlayerUtility::CPlayerUtility()
{
}
void CPlayerUtility::ConstructL(const TDesC& aFileName)
{
generatePlaylog(_L("In Player construct L"));
iPlayUtility = CMdaAudioPlayerUtility::NewFilePlayerL(aFileName, *this);
iPlaying = iPrepared = EFalse;
}
void CPlayerUtility::Play()
{
generatePlaylog(_L("In Player Play IN FunctionL"));
iPlayUtility->Play();
iPlaying = ETrue;
generatePlaylog(_L("In Player Play OUT FunctionL"));
}
void CPlayerUtility::Stop()
{
generatePlaylog(_L("In Player Stop IN FunctionL"));
iPlayUtility->Stop();
iPlaying = EFalse;
generatePlaylog(_L("In Player Stop out FunctionL"));
}
void CPlayerUtility::MapcPlayComplete(TInt aError)
{
generatePlaylog(_L("In Player MapcPlayComplete IN FunctionL"));
if (aError == KErrNone)
{
iPlaying = EFalse;
iPrepared = ETrue;
iPlayUtility->SetVolume(iPlayUtility->MaxVolume());
iPlayUtility->Play();
generatePlaylog(_L("In Player MapcPlayComplete out FunctionL"));
}
else
{
TBuf<50> temp1;
temp1.AppendNum(aError);
generatePlaylog(_L("Error is"));
generatePlaylog(temp1);
}
}
void CPlayerUtility::MapcInitComplete(TInt aError,
const TTimeIntervalMicroSeconds& /*aDuration*/)
{
generatePlaylog(_L("In Player MapcInitComplete IN FunctionL"));
if (aError == KErrNone)
{
iPrepared = ETrue;
iPlayUtility->SetVolume(iPlayUtility->MaxVolume());
iPlayUtility->Play();
}
generatePlaylog(_L("In Player MapcInitComplete out FunctionL"));
}
void CPlayerUtility::generatePlaylog(const TDesC& data)
{
TBuf<500> writedata;
TBuf8<500> writedata8;
TBuf<500> timetext;
TBuf<500> datetext;
TBuf<500> timetext1;
TBuf<500> datetext1;
writedata.Delete(0, 500);
writedata8.Delete(0, 500);
_LIT(KFormat1, "%:0%H%:1%T%:2%S%:3");
_LIT(KDateFormat, "%Y%*M%D%3-%2-%1");
TTime time;
time.HomeTime();
timetext.Delete(0, 50);
datetext.Delete(0, 50);
TDateTime curTime = time.DateTime();
time.FormatL(timetext, KFormat1);
time.FormatL(datetext, KDateFormat);
timetext1.Copy(timetext);
datetext1.Copy(datetext);
writedata.Append(_L("\r\n"));
writedata.Append(data);
writedata.Append(_L(" "));
writedata.Append(datetext1);
writedata.Append(_L(" "));
writedata.Append(timetext1);
writedata8.Copy(writedata);
RFs aFsk1;
aFsk1.Connect();
_LIT(Ktfile1, "C:\\data\\others\\Mobi\\LogFile.txt");
RFs fsSessiona;
fsSessiona.Connect();
RFile filea;
filea.Open(fsSessiona, Ktfile1, EFileWrite);
TInt posa = 0;
filea.Seek(ESeekEnd, posa);
filea.Write(posa, writedata8);
filea.Close();
fsSessiona.Close();
}
when there is request to play i do
iMyPlayer = CPlayerUtility::NewL(KMusicFile);
and when i want to stop playing in that fn code is
if(iMyPlayer)
{
iMyPlayer->Stop();
delete iMyPlayer;
iMyPlayer = NULL;
};
if i remove ifcondition then some time my app crashes at stop fun of player
Please can any one help in solving my problem...
Thanks n advance
Cholker



