Discussion Board
Playing Sound From a Buffer
2003-07-31, 14:18
#1
Registered User
Hi Guys,
Do Anyone know the best way to play a sound which is stored in a buffer on Series 60.
I am currently using the CMdaAudioRecorderUtility class to play the sound, however when Play() is called, I get "System error Try again (-18)".
This is strange because inside the MoscoStateChangeEvent function, the current state of the CMdaAudioRecorderUtility object is EOpen....hence it is ready to play..but it doesn't.
Also I know the buffer I pass is ok because it starts with RIFF1/4WAV which proves that the data in the buffer is .WAV audio content.
here is my code below:
void _CPP_Peer_PlayAudio(int in_wnd, TUint8* soundData, int aDataSize)
{
//The Sound data to Play
TPtr8 dataToPlay( (TUint8*)soundData, aDataSize, aDataSize);
CPlayerAdapter* ptr->iPlayerAdapter = CPlayerAdapter::NewWithDataL(dataToPlay);
}
The CPlayerAdapter is the same one as in S60 examples, but I use CMdaAudioRecorderUtility instead of CMdaAudiopPlayerUtility. Here is the CPlayerAdater code :
CPlayerAdapter::CPlayerAdapter() :
iState(ENotReady)
{
}
CPlayerAdapter* CPlayerAdapter::NewWithDataL(TDes8& aData)
{
CPlayerAdapter* self = NewWithDataLC(aData);
CleanupStack::Pop(); // self
return self;
}
CPlayerAdapter* CPlayerAdapter::NewWithDataLC(TDes8& aData)
{
CPlayerAdapter* self = new (ELeave) CPlayerAdapter();
CleanupStack::PushL(self);
self->ConstructWithDataL(aData);
return self;
}
void CPlayerAdapter::ConstructWithDataL(TDes8& aData)
{
iMdaAudioRecorderUtility = CMdaAudioRecorderUtility::NewL(*this);
// Open an existing sample file for playback or recording causes MMdaObjectStateChangeObserver::MoscoStateChangeEvent to be called
iMdaAudioRecorderUtility->OpenDesL(aData);
}
// from MMdaObjectStateChangeObserver
void CPlayerAdapter::MoscoStateChangeEvent(CBase* /*aObject*/, TInt aPreviousState, TInt aCurrentState, TInt aErrorCode)
{
switch (iMdaAudioRecorderUtility->State())
{
case CMdaAudioRecorderUtility::EOpen:
{
iState = EReadyToPlay;
PlayL();
}
default:
;
}
}
void CPlayerAdapter::PlayL()
{
// Play through the device speaker
iMdaAudioRecorderUtility->SetAudioDeviceMode(CMdaAudioRecorderUtility::ELocal);
// Set maximum volume for playback
iMdaAudioRecorderUtility->SetVolume(iMdaAudioRecorderUtility->MaxVolume());
// Set the playback position to the start of the file
iMdaAudioRecorderUtility->SetPosition(TTimeIntervalMicroSeconds(0));
//
iMdaAudioRecorderUtility->PlayL();
iState = EPlaying;
CEikonEnv::Static()->InfoMsg(_L("Playing"));
}
As soon as iMdaAudioRecorderUtility->PlayL(); is called I get error code -18.
The funny thing is that if I supply a filename then the sound plays fine but it can't play with a buffer.
Any help or examples would be greatly appreciated!!!!
or does anyone have a better way to play sounds from a buffer??
about play raw data buffer
2003-08-01, 03:43
#2
Registered User
you may try those source codes.
1. #include <mdaaudiooutputstream.h>
#include <mda\common\audio.h>
2. import mediaclientaudiostream.lib
3. inheriting class MMdaAudioOutputStreamCallback
4. declare this methids:
public:
void OpenStream();
virtual void MaoscOpenComplete(TInt aError);
virtual void MaoscBufferCopied(TInt aError, const TDesC8& );
virtual void MaoscPlayComplete(TInt aError);
private:
CMdaAudioOutputStream* iStream;
TMdaAudioDataSettings iSettings;
5. Implement class methods:
void [class name]::OpenStream() {
iStream = CMdaAudioOutputStream::NewL(*this);
iStream->Open(&iSettings);
}
void [class name]::MaoscOpenComplete(TInt aError) {
if (aError==KErrNone) {
iStream->SetAudioPropertiesL(TMdaAudioDataSettings::ESampleRate8000Hz, TMdaAudioDataSettings::EChannelsMono);
iStream->SetVolume(iStream->MaxVolume());
iStream->SetPriority(EPriorityMuchMore, EMdaPriorityPreferenceNone);
}
}
void [class name]::MaoscBufferCopied(TInt aError, const TDesC8& )
{
if (aError==KErrNone) {
}
}
void [class name]::MaoscPlayComplete(TInt aError) {
if (aError==KErrUnderflow) {
}
}
6. if that code was prepared , you can use the sample code to play buffer.
TInt16* TmpBuffer2 = new TInt16[BUFFERSIZE];
Mem::Copy(TmpBuffer2,TmpWaveStream,BUFFERSIZE);
TPtr8* iTmpBuf = new TPtr8((TUint8*)TmpBuffer2, BUFFERSIZE, BUFFERSIZE*2);
iStream->WriteL(*iTmpBuf);
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules