×
Namespaces

Variants
Actions

Playing audio tones

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Article
Created: symbianyucca (22 Mar 2007)
Last edited: hamishwillee (14 Jun 2013)

The CTonePlayer example illustrates how to play tones on Symbian devices. This example plays a simple constant tone for a predefined time, but CMdaAudioToneUtility could also be used to play DTMF (Dual-Tone Multi-Frequency) strings and tone sequences.

To use CMdaAudioToneUtility you need to implement MMdaAudioToneObserver callback interface, which is used by the player to update its status. MMdaAudioToneObserver has two methods defined from which MatoPrepareComplete is called when the tone player is initialized and ready to play. Play function should never be called before MatoPrepareComplete is called. The MatoPlayComplete method is called after the playing of the tone has finalized.


TonePlayer.cpp

#include <MdaAudioTonePlayer.h>
#include <eikmenup.h>
 
 
CTonePlayer* CTonePlayer::NewL()
{
CTonePlayer* self = NewLC();
CleanupStack::Pop(self);
return self;
}
 
CTonePlayer* CTonePlayer::NewLC()
{
CTonePlayer* self = new (ELeave) CTonePlayer();
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
 
CTonePlayer::CTonePlayer(): iFrequency(125),iDuration(5000000)
{
}
 
CTonePlayer::~CTonePlayer()
{
delete iToneUtility;
}
 
void CTonePlayer::ConstructL()
{
iToneUtility = CMdaAudioToneUtility::NewL(*this);
iToneUtility->PrepareToPlayTone(iFrequency,iDuration);
}
 
void CTonePlayer::Play()
{
iToneUtility->Play();
}
 
void CTonePlayer::Stop()
{
iToneUtility->CancelPlay();
}
 
void CTonePlayer::MatoPrepareComplete(TInt /*aError*/)
{
iToneUtility->SetVolume(iToneUtility->MaxVolume());
}
 
void CTonePlayer::MatoPlayComplete(TInt /*aError*/)
{
}


TonePlayer.h

#include <e32std.h>
#include <MdaAudioTonePlayer.h>
 
 
class CTonePlayer : public CBase, public MMdaAudioToneObserver
{
public:
static CTonePlayer* NewL();
static CTonePlayer* NewLC();
~CTonePlayer();
public:
void Play();
void Stop();
protected: // from MMdaAudioToneObserver
void MatoPrepareComplete(TInt aError);
void MatoPlayComplete(TInt aError);
private:
CTonePlayer();
void ConstructL();
private:
CMdaAudioToneUtility* iToneUtility;
TInt iFrequency;
TTimeIntervalMicroSeconds iDuration;
};
 
This page was last modified on 14 June 2013, at 07:52.
38 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×