📄 soundmanager.cpp
字号:
/*
* ============================================================================
* Name : CSoundManager from SoundManager.cpp
* Part of : Mopoid
* Created : 16.01.2004 by Andreas Jakl / Mopius - http://www.mopius.com/
* Description:
* Manages handling of multiple sound files.
* Version : 1.02
* Copyright:
* 'Mopoid' is free software; you can redistribute
* it and/or modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* 'Mopoid' is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with 'Mopoid'; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* ============================================================================
*/
#include "soundManager.h"
/// Constructors
CSoundManager::CSoundManager()
{
for (int i = 0; i < MAX_SOUNDS; i++)
iSounds[i] = NULL;
iSoundOn = true;
}
/// Destructor
CSoundManager::~CSoundManager()
{
for (int i = 0; i < MAX_SOUNDS; i++)
{
if (iSounds[i])
DELETE_AND_NULL(iSounds[i]);
}
}
void CSoundManager::LoadSoundFileL(const TDesC& aSoundFileName, TInt aSoundNumber)
{
if (aSoundNumber >= 0 && aSoundNumber < MAX_SOUNDS)
{
TFileName fullName(aSoundFileName);
CompleteWithAppPath(fullName);
#ifdef __WINS__
fullName[0] = 'C';
#endif
iSounds[aSoundNumber] = CPlayerAdapter::NewL(fullName);
}
}
void CSoundManager::PlayL(TInt aSoundNumber)
{
if (iSoundOn && iSounds[aSoundNumber])
{
// Stop all sounds as we can't play two sounds at the same time.
for (int i=0; i < MAX_SOUNDS; i++)
{
if (iSounds[i])
iSounds[i]->StopL();
}
// Now, finally we can play our sound.
iSounds[aSoundNumber]->PlayL();
}
}
void CSoundManager::Stop(TInt aSoundNumber)
{
if (iSoundOn)
{
TRAPD(error, iSounds[aSoundNumber]->StopL());
}
}
void CSoundManager::SetVolume(const TInt aSoundLevel)
{
if (aSoundLevel == VOLUME_OFF)
{
iSoundOn = false;
}
else
{
iSoundOn = true;
for (int i=0; i < MAX_SOUNDS; i++)
{
if (iSounds[i])
iSounds[i]->SetVolumeFraction(aSoundLevel);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -