⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ttsplayer.cpp

📁 了解 Symbian Operation Symtem C++ S60 的基本开发
💻 CPP
字号:
/*
* ============================================================================
*  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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -