modify audiomanager

This commit is contained in:
侯歌 2024-07-17 22:26:04 +08:00
parent c1248841e0
commit aebf77b595
2 changed files with 40 additions and 1 deletions

View File

@ -1,8 +1,38 @@
#include <core/audiomanager.h>
#include <view/soundeffectconstants.h>
//#include <rtaudio/RtAudio.h>
namespace cdroid{
void AudioManager::playSoundEffect(int effectType){
/*static int rtAudioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBufferFrames,
double streamTime, RtAudioStreamStatus status, void *userData){
return 0;
}*/
AudioManager::AudioManager(){
mContext = nullptr;
}
AudioManager::AudioManager(Context*ctx):AudioManager(){
setContext(ctx);
}
void AudioManager::setContext(Context* context){
mSoundEffects.put(SoundEffectConstants::CLICK,"click");
mSoundEffects.put(SoundEffectConstants::NAVIGATION_LEFT,"navigation_left");
mSoundEffects.put(SoundEffectConstants::NAVIGATION_UP,"navigation_up");
mSoundEffects.put(SoundEffectConstants::NAVIGATION_RIGHT,"navigation_right");
mSoundEffects.put(SoundEffectConstants::NAVIGATION_DOWN,"navigation_down");
mSoundEffects.put(SoundEffectConstants::NAVIGATION_REPEAT_LEFT,"navigation_repeat_left");
mSoundEffects.put(SoundEffectConstants::NAVIGATION_REPEAT_UP,"navigation_repeat_up");
mSoundEffects.put(SoundEffectConstants::NAVIGATION_REPEAT_RIGHT,"navigation_repeat_right");
mSoundEffects.put(SoundEffectConstants::NAVIGATION_REPEAT_DOWN,"navigation_repeat_down");
for(int i=SoundEffectConstants::CLICK;i<=SoundEffectConstants::NAVIGATION_REPEAT_DOWN+1;i++)
playSoundEffect(i);
}
void AudioManager::playSoundEffect(int effectType){
const std::string res = mSoundEffects.get(effectType,"");
LOGD("%d=%s",effectType,res.c_str());
}
void AudioManager::playSoundEffect(int effectType, float volume){

View File

@ -1,8 +1,17 @@
#ifndef __AUDIO_MANAGER_H__
#define __AUDIO_MANAGER_H__
#include <core/sparsearray.h>
namespace cdroid{
class Context;
class AudioManager{
private:
Context*mContext;
SparseArray<std::string>mSoundEffects;
private:
void setContext(Context* context);
public:
AudioManager();
AudioManager(Context*);
void playSoundEffect(int effectType);
void playSoundEffect(int effectType, float volume);
};