×

Discussion Board

Results 1 to 1 of 1
  1. #1
    Regular Contributor
    Join Date
    Feb 2009
    Posts
    188

    CMdaAudioOutputStream play mp3 slowly

    i am using following code to stream mp3 audio. but it plays mp slowly. what is wrong in my code. 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:
    case EAudioStreamingPlay:
    			{
    
                             _LIT(KFileName, "\\data\\song.mp3");
    			// 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;
    			}
    
    Last edited by kuddy_abc; 2010-05-18 at 06:30.

Similar Threads

  1. SymPlayer – Wirelessly Play MP3 files directly from computer
    By hedge777 in forum News and Announcements
    Replies: 0
    Last Post: 2010-01-25, 02:27
  2. Problem of using CMMFDevSound to play mp3
    By stone_cheng in forum Symbian Media (Closed)
    Replies: 4
    Last Post: 2009-04-11, 16:09
  3. Replies: 1
    Last Post: 2008-06-17, 10:40
  4. Unable to play mp3 by CMdaAudioOutputStream
    By anand_zain76 in forum Symbian Media (Closed)
    Replies: 5
    Last Post: 2008-03-11, 13:57

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×