Namespaces
Variants
Actions

Playing audio tones

Jump to: navigation, search
Article Metadata

Article
Created: symbianyucca (22 Mar 2007)
Last edited: hamishwillee (25 Jul 2012)

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 25 July 2012, at 09:18.
87 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved