在Symbian S60中播放声音

时间:2011-02-13 01:13:18

标签: audio symbian multimedia s60

我是Symbian的新手,我无法播放声音。我看了很多例子,我找不到我的错误。有没有其他人有这方面的经验?任何方向都会有所帮助。我用另一个班级的计时器打电话给Play。

头:

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 个答案:

答案 0 :(得分:1)

诺基亚论坛上的那些人帮助了我,这是最终结果

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();
}

链接到论坛帖子http://discussion.forum.nokia.com/forum/showthread.php?219262-Playing-the-current-massage-tone&p=819083#post819083