ttsplayer.cpp

来自「了解 Symbian Operation Symtem C++ S60 的基本开」· C++ 代码 · 共 81 行

CPP
81
字号
/*
* ============================================================================
*  Name     : TtsPlayer.cpp
*  Part of  : TextToSpeech example
*  Created  : 05.07.2006 by Artem Marchenko
*  Description:
*     TtsPlayer.cpp - source file
*  Version  : 1.0
*  Copyright: Artem Marchenko 2006, http://symbianexample.com
* ============================================================================
*/


//  Include Files  

#include <e32base.h>
#include <e32std.h>
#include <e32def.h>
#include "TtsPlayer.h"

// Prefix telling the audio utility that TTS should be used
_LIT( KTtsPrefix, "(tts)" );

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

CTtsPlayer::~CTtsPlayer()
	{
	delete iWaiter;
	delete iPlayer;
	}

void CTtsPlayer::ConstructL()
	{
	iPlayer = CMdaAudioPlayerUtility::NewL( *this );
	iWaiter = new (ELeave) CActiveSchedulerWait;
	}

void CTtsPlayer::PlayTextL( TDesC& aText )
	{
	__ASSERT_ALWAYS( iPlaybackInProgress == EFalse, User::Leave( KErrNotReady ) );
	HBufC8* playableText = HBufC8::NewLC( aText.Length() + KTtsPrefix().Length() );
	playableText->Des().Append( KTtsPrefix );
	playableText->Des().Append( aText );
	iPlayer->OpenDesL( *playableText );
	iPlaybackInProgress = ETrue;
	iWaiter->Start();
	// At this point playback is already completed or failed 
	User::LeaveIfError( iErr );
	CleanupStack::PopAndDestroy( playableText );
	}
	
void CTtsPlayer::MapcInitComplete( TInt aError, const TTimeIntervalMicroSeconds& /*aDuration*/ )
	{
	iErr = aError;
	if( aError != KErrNone ) 
		{
		iPlaybackInProgress = EFalse;
        // Let the paused PlayTextL complete
		iWaiter->AsyncStop();
		}
	else
		{
		iPlayer->Play();
		}
	}

void CTtsPlayer::MapcPlayComplete( TInt aError )
	{
	iErr = aError;
	iPlaybackInProgress = EFalse;
    // Let the paused PlayTextL complete
	iWaiter->AsyncStop();
	}
// End of file

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?