// EIKSNDPY.CPP
//
// Copyright (c) 1997-1999 Symbian Ltd.  All rights reserved.
//

#include <eiksndpy.h>
#include <eikenv.h>

const TInt KEikAlawBufferSize=8000;

//
// CEikAlarmSoundPlayer class
//

CEikAlarmSoundPlayer::CEikAlarmSoundPlayer()
	//
	// private c'tor
	//
    {}

EXPORT_C CEikAlarmSoundPlayer::~CEikAlarmSoundPlayer() 
    {
	Stop();
	delete iSoundPlayer;
	}

EXPORT_C CEikAlarmSoundPlayer *CEikAlarmSoundPlayer::NewL()
	{
	CEikAlarmSoundPlayer *This = new(ELeave) CEikAlarmSoundPlayer();
	CleanupStack::PushL(This);
	This->ConstructL();
	CleanupStack::Pop();
	return(This);
	}

void CEikAlarmSoundPlayer::ConstructL()
	{
	iSoundPlayer=CSoundPlayer::NewL(*this,iSoundDev);
	}

EXPORT_C TInt CEikAlarmSoundPlayer::Play(RFs& aFsSession,const TName& aName)
	{
	if (!(aName.Length()))
		return KErrNone;
	if (IsPlaying())
		return KErrInUse;
	TInt err=iSoundDev.Open();
	if (err)
		return err;
	TSoundConfig config;
	iSoundDev.Config(config);
	config().iVolume=EVolumeMedium;
	config().iAlawBufferSize=KEikAlawBufferSize;
	err=iSoundDev.SetConfig(config);
	if (err==KErrNone)
		{
		TRAP(err,iSoundPlayer->PlaySoundL(aName,aFsSession));
		}
	if (err!=KErrNone)
		iSoundDev.Close();
	return err;
	}

EXPORT_C void CEikAlarmSoundPlayer::Stop()
	{
	if (iSoundPlayer)
		iSoundPlayer->Stop();
	iSoundDev.Close();
	}

EXPORT_C TBool CEikAlarmSoundPlayer::IsPlaying() const
	{
	return (iSoundPlayer->IsPlaying());
	}

void CEikAlarmSoundPlayer::PlayComplete(TInt aStatus)
	//
	// Called when the sound has finsished playing
	//
	{
	iSoundDev.Close();
	if (aStatus)
		CEikonEnv::Static()->HandleError(aStatus);
	}
