Code:
// myapp.h
#include <aknsoundsystem.h>
const TInt KSnapSoundId = 2;
class MyClass
{
...
private:
CAknKeySoundSystem* iCameraSound;
};
void MyClass::ConstructL()
{
...
iCameraSound =
static_cast<CAknAppUi*>(CEikonEnv::Static()->AppUi())->KeySounds();
if (iCameraSound)
{
TRAPD(error, iCameraSound->AddAppSoundInfoListL(
R_CAMERA_SNAP_SOUND));
if ((error != KErrAlreadyExists) && (error != KErrNone))
{
User::LeaveIfError(error);
}
}
}
void MyClass::PlaySnapSound()
{
iCameraSound->PlaySound(KSnapSoundId);
}
在你的.RSS资源文件中添加下面的代码
Code:
#define KcameraSoundFile
"Z:\\system\\sounds\\digital\\Camera1a_2_8kHz.wav"
#define KSnapSoundId 2
RESOURCE AVKON_SOUND_INFO_LIST r_camera_snap_sound
{
list =
{
AVKON_SOUND_INFO
{
sid = KSnapSoundId;
priority = 45;
preference = EAknAudioPrefCamera; // defined in avkon.hrh
file = KCameraSoundFile;
}
};
}