Playing a sound in Symbian S60

382 views Asked by At

I am very much a newbie with Symbian, I am having trouble getting a sound to play on. I've looked at numerous examples and I cannot find my error. Has anyone else had experience with this? Any sort of direction would be helpful. I call Play on with a timer from another class.

header:

class TonePlayer : public CBase, public MMdaAudioPlayerCallback
{
public:
    static TonePlayer* NewL();
    static TonePlayer* NewLC();
    ~TonePlayer();

    void Play();
    void Stop();

protected:
    TonePlayer();

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

private:
    CMdaAudioPlayerUtility* m_pAudioPlayer;

    void ConstructL();
};

cpp:

TonePlayer* TonePlayer::NewL()
{
    TonePlayer* self = NewLC();
    CleanupStack::Pop(self);  
    return self;
}

TonePlayer* TonePlayer::NewLC()
{
    TonePlayer* self = new (ELeave) TonePlayer();
    CleanupStack::PushL(self);
    self->ConstructL();
    return self;
}

TonePlayer::TonePlayer()
{
}

TonePlayer::~TonePlayer()
{
    delete m_pAudioPlayer;
    m_pAudioPlayer = NULL;
}

void TonePlayer::ConstructL()
{
    m_pAudioPlayer = CMdaAudioPlayerUtility::NewL(*this);
}

void TonePlayer::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds &aDuration)
{
    MProEngEngine* pProfileEngine = ProEngFactory::NewEngineLC();
    MProEngProfile* pProfile = pProfileEngine->ActiveProfileL();
    MProEngTones& oTones = pProfile->ProfileTones();

    m_pAudioPlayer->OpenFileL(oTones.MessageAlertTone());
    m_pAudioPlayer->SetVolume(m_pAudioPlayer->MaxVolume());

    Play();

    delete pProfileEngine;
}

void TonePlayer::MapcPlayComplete(TInt aError)
{
}

void TonePlayer::Play()
{   
    m_pAudioPlayer->Play();
}

void TonePlayer::Stop()
{
    m_pAudioPlayer->Stop();
}
1

There are 1 answers

0
micheal blunning On

The guys over at Nokia Forum helped me out, here is the final result

TonePlayer* TonePlayer::NewL()
{
    TonePlayer* self = NewLC();
    CleanupStack::Pop(self); 
    return self;
}

TonePlayer* TonePlayer::NewLC()
{
    TonePlayer* self = new (ELeave) TonePlayer();
    CleanupStack::PushL(self);
    self->ConstructL();
    return self;
}

TonePlayer::TonePlayer()
{
}

TonePlayer::~TonePlayer()
{
    delete m_pAudioPlayer;
    m_pAudioPlayer = NULL;
}

void TonePlayer::ConstructL()
{
    MProEngEngine* pProfileEngine = ProEngFactory::NewEngineLC();
    MProEngProfile* pProfile = pProfileEngine->ActiveProfileLC();
    MProEngTones& oTones = pProfile->ProfileTones();

    m_pAudioPlayer = CMdaAudioPlayerUtility::NewFilePlayerL(oTones.MessageAlertTone(), *this);

    CleanupStack::PopAndDestroy(2);
}

void TonePlayer::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds &aDuration)
{
    if( aError == KErrNone  )
    {
        m_pAudioPlayer->SetVolume(m_pAudioPlayer->MaxVolume());
    }
}

void TonePlayer::MapcPlayComplete(TInt aError)
{
}

void TonePlayer::Play()
{   

    m_pAudioPlayer->Play();
}

void TonePlayer::Stop()
{
    m_pAudioPlayer->Stop();
}

link to forum post http://discussion.forum.nokia.com/forum/showthread.php?219262-Playing-the-current-massage-tone&p=819083#post819083