首 页 | 新 闻 | Symbian | Android| Windows Mobile | J2ME | 下载中心 | 游戏策划招聘与求职 | 购书指南 | 视频教程
您现在的位置: 开发视界 >> Symbian英文资料 >> Multimedia >> 正文
Playing a WAV file
作者:佚名    文章来源:不详    更新时间:2006-5-6 22:40:51

Playing a WAV file is easier as it may look at first sight since the OS does most of the work. In this project the class CSoundPlayer implements all the necessary stuff to do this:


#include <MdaAudioSamplePlayer.h>

class CSoundPlayer: public CBase, public MMdaAudioPlayerCallback
{
public:
   static CSoundPlayer* NewL(const TDesC& aFile);
   static CSoundPlayer* NewLC(const TDesC& aFile);
   ~CSoundPlayer();
   void PlayL();
   void StopL();

   //
   // from MMdaAudioPlayerCallback
   //
   void MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& aDuration);
   void MapcPlayComplete(TInt aError);

private:
   CSoundPlayer();
   void ConstructL(const TDesC& aFile);

private:
   enum TState
   {
       ENotReady,
       EReady,
       EPlaying
   };

   TState iState;
   CMdaAudioPlayerUtility* iMdaPlayer;
};

The key classes are :
-  CMdaAudioPlayerUtility which implements the decoder. The class CSoundPlayer has a private member of this class called iMdaPlayer.
-  MMdaAudioPlayerCallback which is a kind of observer on iMdaPlayer. Basically this mixin class requires the implementation of the MapcInitComplete() and MapcPlayComplete() which will be described below.

Initialisation of the player

The player is initialised by calling CSoundPlayer::NewL() or CSoundPlayer::NewLC(). The second-phase constructor of the CSoundPlayer object will initialise the iMdaPlayer object using CMdaAudioPlayerUtility::NewFilePlayerL():


void CSoundPlayer::ConstructL(const TDesC& aFile)
{
 //
 // Create a file audio player utility instance
 //
 iMdaPlayer=CMdaAudioPlayerUtility::NewFilePlayerL(aFile,*this);
}

A second type of constructor, CMdaAudioPlayerUtility::NewDesPlayerL() is available if your WAV sample is already in RAM memory.

The player is not ready to play yet. Actually, if you try to call iMdaPlayer->PlayL() right after the NewFilePlayerL() call, you will probably hear nothing: you have to wait the player instance constuction to be ready to play. It will be signalled to you when the callback method MapcInitComplete() is called by the framework. Two typical implementation of this function are shown below:


//
// Implementation 1: set a iState flag to ready
// to reflect the fact that the player is ready
//
void CSoundPlayer::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& /*aDuration*/)
{
   iState = aError ? ENotReady : EReady;
}


//
// Implementation 2: play the file immediately
//
void CSoundPlayer::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& /*aDuration*/)
{
   if (!aError)
       iMdaPlayer->PlayL();
}

Playing the file

Once the initialisation is complete, and as shown is the code above, the playback of the file is asked by a call to CMdaAudioPlayerUtility::PlayL(). In the Sound1 project, this is done by calling CSoundPlayer::PlayL():


void CSoundPlayer::Play()
{
   if(iState==EReady)
   {
       iState=EPlaying;
       iMdaPlayer->Play();
   }
}

The framework will notify you the end of the playback by a call to MapcPlayComplete(). Here is the implementation for Sound1:


void CSoundPlayer::MapcPlayComplete(TInt aError)
{
   iState = aError ? ENotReady : EReady;
}

 



In order to run this example, you must put a WAV file called play.wav in the directory C:\System\Apps\Sound\ of your device (C:\Symbian\6.1\Series60\Epoc32\Wins\c\system\apps\Sound under the simulator).
相关文章:
How to reset the alternate makmake entry in Codewarrior
Carbide.vs - Disabling the MMP/PKG File update feature
Codewarrior: how to avoid the "Too Many Include Paths" error when using the UIQ 2.1 SDK
Carbide.c++: Setting up On Target Debugging
Display the extended panic code in Emulator or Device
Start automatically an application or an exe after its installation
Compress Your Symbian C++ Executables
How To Freeze New Exports From Dll
 

站点地图 | 加入收藏 | 联系站长 | 广告服务 |
QQ:280529124  Tel:0592-8271361 辽ICP备05021703号