4

特定のサウンドをループするためにSoundPool関数を使用するSoundManagerクラスを作成しましたが、サウンドが再生されない理由がわかりません。

public class SoundManager {
private  SoundPool mSoundPool; 
private  HashMap<Integer, Integer> mSoundPoolMap; 
private  AudioManager  mAudioManager;
private  Context mContext;

public SoundManager()
{

}

public void initSounds(Context theContext) { 
     mContext = theContext;
     mSoundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 0); 
     mSoundPoolMap = new HashMap<Integer, Integer>(); 
     mAudioManager = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);         
} 

public void addSound(int Index, int SoundID) {
    mSoundPoolMap.put(Index, mSoundPool.load(mContext, SoundID, 1));
}

public void playSound(int index) { 
     int streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC); 
     mSoundPool.play(mSoundPoolMap.get(index), streamVolume, streamVolume, 1, 0, 1f); 
}

public void playLoopedSound(int index) { 
     int streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC); 
     mSoundPool.play(mSoundPoolMap.get(index), streamVolume, streamVolume, 1, -1, 1f); 
}

}

このクラスは、私のアクティビティから次の方法で呼び出されています。

private SoundManager mSoundManager;
mSoundManager = new SoundManager();
mSoundManager.initSounds(getBaseContext());
mSoundManager.addSound(1, R.raw.sound);
mSoundManager.playSound(1);
4

2 に答える 2

2

どうやら私のアクティビティの onCreate では動作しませんが、イベントが発生したときに呼び出します (インテント/キープレス) 動作するようです

于 2010-07-24T04:49:29.623 に答える
1

私はこの問題を抱えていましたが、オーディオをサポートするエミュレーターで実行することで最終的に解決しました!!

こんなに簡単だったなんて信じられない!

ウィンドウ>AVDマネージャー>AVDを編集します(スナップショットから実行していたため、安全のために新しいものを作成しました)>ハードウェア>新規>オーディオ再生のサポート

于 2012-05-18T19:55:18.410 に答える