i am using following code to stream mp3 audio. but it plays music slowly? what is work. please help me
header
---------
HTML Code:#ifndef AUDIOSTREAMPLAYER_H #define AUDIOSTREAMPLAYER_H // INCLUDE FILES #include <e32std.h> #include <e32base.h> #include <MdaAudioOutputStream.h> // FORWARD DECLARATION class RFs; // CLASS DECLARATION class CAudioStreamPlayer : public CBase, public MMdaAudioOutputStreamCallback { public: // Constructors and destructor static CAudioStreamPlayer* NewL(); static CAudioStreamPlayer* NewLC(); ~CAudioStreamPlayer(); public: // Public methods void PlayL(RFs& aFs, const TDesC& aFileName); void Stop(); private: // Constructors CAudioStreamPlayer(); void ConstructL(); private: // From MMdaAudioOutputStreamCallback void MaoscOpenComplete(TInt aError); void MaoscBufferCopied(TInt aError, const TDesC8& aBuffer); void MaoscPlayComplete(TInt aError); private: // Private methods void DisplayErrorMessage(TInt aError); private: CMdaAudioOutputStream* iAudioStream; RFile iFile; RBuf8 iBuffer; }; #endif // AUDIOSTREAMPLAYER_H
source
---------
HTML Code:/ INCLUDE FILES #include <eikenv.h> #include <mda/common/audio.h> #include "AudioStreamPlayer.h" // CONSTANTS const TInt KMaxBuffer = 8192; // 8 KB buffer const TInt KVolumeDenominator = 2; // METHODS DEFINITION CAudioStreamPlayer::CAudioStreamPlayer() { } CAudioStreamPlayer::~CAudioStreamPlayer() { delete iAudioStream; iFile.Close(); iBuffer.Close(); } CAudioStreamPlayer* CAudioStreamPlayer::NewLC() { CAudioStreamPlayer* self = new (ELeave)CAudioStreamPlayer(); CleanupStack::PushL(self); self->ConstructL(); return self; } CAudioStreamPlayer* CAudioStreamPlayer::NewL() { CAudioStreamPlayer* self=CAudioStreamPlayer::NewLC(); CleanupStack::Pop(self); return self; } void CAudioStreamPlayer::ConstructL() { iBuffer.CreateL(KMaxBuffer); iAudioStream = CMdaAudioOutputStream::NewL(*this); } void CAudioStreamPlayer::PlayL(RFs& aFs, const TDesC& aFileName) { Stop(); // Open the file for reading. iFile.Close(); User::LeaveIfError(iFile.Open(aFs, aFileName, EFileRead)); // Open the audio device for streaming. iAudioStream->Open(NULL); } void CAudioStreamPlayer::Stop() { iAudioStream->Stop(); } void CAudioStreamPlayer::MaoscOpenComplete(TInt aError) { if (KErrNone == aError) { // Read the buffer. iFile.Read(iBuffer, KMaxBuffer); // Set the data type. TInt err = KErrNone; TRAP(err, iAudioStream->SetDataTypeL(KMMFFourCCCodeMP3)); if (KErrNone == err) { // Set the sampling rate and number of channels. TRAP(err, iAudioStream->SetAudioPropertiesL( TMdaAudioDataSettings::ESampleRate44100Hz, TMdaAudioDataSettings::EChannelsMono)); if (KErrNone == err) { // Set volume and play it. iAudioStream->SetVolume( iAudioStream->MaxVolume() / KVolumeDenominator); TRAP(err, iAudioStream->WriteL(iBuffer)); } } if (KErrNone != err) { DisplayErrorMessage(err); } } else { // Do something when error happens. DisplayErrorMessage(aError); } } void CAudioStreamPlayer::MaoscBufferCopied(TInt aError, const TDesC8& /*aBuffer*/) { if (KErrNone == aError) { // Read the next buffer. iFile.Read(iBuffer, KMaxBuffer); TRAPD(err, iAudioStream->WriteL(iBuffer)); if (KErrNone != err) { DisplayErrorMessage(err); } } else { // Do something when error happens. } } void CAudioStreamPlayer::MaoscPlayComplete(TInt /*aError*/) { iFile.Close(); } void CAudioStreamPlayer::DisplayErrorMessage(TInt aError) { const TInt KMaxBuffer = 15; _LIT(KErrorMessage, "Error: %d"); TBuf<KMaxBuffer> buffer; buffer.AppendFormat(KErrorMessage, aError); TRAP_IGNORE(CEikonEnv::Static()->InfoWinL(buffer, buffer)); } // End of File
AppUI
----------
HTML Code:. _LIT(KFileName, "\\data\\song.mp3"); . . . case EAudioStreamingPlay: { // Construct file name. // It adds drive letter to KFileName, where drive letter // is the same as the application's executable. TParsePtrC parseAppPath(Application()->AppFullName()); TParse parseFileName; parseFileName.Set(parseAppPath.Drive(), 0, &KFileName); // Play the audio clip. iAudioPlayer->PlayL(iCoeEnv->FsSession(), parseFileName.FullName()); break; } . . .



