sl@0: // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0: // All rights reserved.
sl@0: // This component and the accompanying materials are made available
sl@0: // under the terms of "Eclipse Public License v1.0"
sl@0: // which accompanies this distribution, and is available
sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0: //
sl@0: // Initial Contributors:
sl@0: // Nokia Corporation - initial contribution.
sl@0: //
sl@0: // Contributors:
sl@0: //
sl@0: // Description:
sl@0: //
sl@0: 
sl@0: #include "CapTestStep0014.h"
sl@0: 
sl@0: CAudPlayUtilTS0014* CAudPlayUtilTS0014::NewL()
sl@0: 	{
sl@0: 	CAudPlayUtilTS0014* self = new (ELeave) CAudPlayUtilTS0014;
sl@0: 	CleanupStack::PushL(self);
sl@0: 	self->ConstructL();
sl@0: 	CleanupStack::Pop();
sl@0: 	return self;
sl@0: 	}
sl@0: 	
sl@0: void CAudPlayUtilTS0014::ConstructL()
sl@0: 	{
sl@0: 	// Create the audio player
sl@0: 	iInternalState = EStateNone;
sl@0: 	iPlayer = CMdaAudioRecorderUtility::NewL(*this, NULL, EMdaPriorityMax);
sl@0: 	}
sl@0: 	
sl@0: 
sl@0: void CAudPlayUtilTS0014::StartProcessing(TRequestStatus& aStatus)
sl@0: 	{
sl@0: 	iStatus = &aStatus;
sl@0: 	iInternalState = EStatePending;
sl@0: 
sl@0: 	iPlayer->OpenFileL(_L("c:\\rectest1.wav"));
sl@0: 	CActiveScheduler::Start();
sl@0: 	}
sl@0: 		
sl@0: 		
sl@0: TVerdict CAudPlayUtilTS0014::EndProcessingAndReturnResult(TDes8& aMessage)
sl@0: 	{
sl@0: 	iPlayer->Close();
sl@0: 	aMessage.Copy(_L("Done"));
sl@0: 	return iVerdict;
sl@0: //	return EPass;
sl@0: 	}
sl@0: 	
sl@0: void CAudPlayUtilTS0014::MoscoStateChangeEvent(CBase* /*aObject*/, TInt aPreviousState, TInt aCurrentState, TInt aErrorCode)
sl@0: 	{
sl@0: 	if (aErrorCode == KErrNone)
sl@0: 		{
sl@0: 		if (aPreviousState == CMdaAudioClipUtility::ENotReady && aCurrentState==CMdaAudioClipUtility::EOpen)
sl@0: 			{
sl@0: 			iPlayer->RecordL();
sl@0: 			}
sl@0: 		else if (aPreviousState == CMdaAudioClipUtility::EOpen && aCurrentState==CMdaAudioClipUtility::ERecording)
sl@0: 			{
sl@0: 			if(iInternalState == EStatePending)
sl@0: 				{
sl@0: 				User::RequestComplete(iStatus, KErrNone);
sl@0: 				iInternalState = EStateComplete;
sl@0: 				}
sl@0: 			}
sl@0: 		else if (aPreviousState == CMdaAudioClipUtility::ERecording && aCurrentState==CMdaAudioClipUtility::EOpen)
sl@0: 			{
sl@0: 			// this shouldn't happen as record will continue until interrupted
sl@0: 			iVerdict = EPass;
sl@0: 			CActiveScheduler::Stop();
sl@0: 			if(iInternalState == EStatePending)
sl@0: 				{
sl@0: 				User::RequestComplete(iStatus, KErrCancel);
sl@0: 				iInternalState = EStateComplete;
sl@0: 				}
sl@0: 			}
sl@0: 		}
sl@0: 	else if (aErrorCode == KErrInUse)
sl@0: 		{
sl@0: 		// double check state to ensure behaviour is correct
sl@0: 		if (aPreviousState == CMdaAudioClipUtility::ERecording && aCurrentState==CMdaAudioClipUtility::EOpen)
sl@0: 			{
sl@0: 			iVerdict = EPass;
sl@0: 			CActiveScheduler::Stop();
sl@0: 			if(iInternalState == EStatePending)
sl@0: 				{
sl@0: 				User::RequestComplete(iStatus, KErrNone);
sl@0: 				iInternalState = EStateComplete;
sl@0: 				}
sl@0: 			}
sl@0: 		}
sl@0: 
sl@0: 	else 
sl@0: 		{
sl@0: 		iVerdict = EFail;
sl@0: 		CActiveScheduler::Stop();
sl@0: 		if(iInternalState == EStatePending)
sl@0: 			{
sl@0: 			User::RequestComplete(iStatus, aErrorCode);
sl@0: 			iInternalState = EStateComplete;
sl@0: 			}
sl@0: 		}
sl@0: 
sl@0: 	}
sl@0: 
sl@0: 
sl@0: CAudPlayUtilTS0014::~CAudPlayUtilTS0014()
sl@0: 	{
sl@0: 	delete iPlayer;
sl@0: 	}