SoundPoolUtil.java 913 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package com.edufound.base.util;
  2. import android.content.Context;
  3. import android.media.AudioManager;
  4. import android.media.SoundPool;
  5. public class SoundPoolUtil {
  6. SoundPool soundPool;
  7. boolean isLoadComplete = false;
  8. public void init(Context context, int rawId) {
  9. soundPool = new SoundPool(10, AudioManager.STREAM_SYSTEM, 5);
  10. soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
  11. @Override
  12. public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
  13. isLoadComplete = true;
  14. }
  15. });
  16. soundPool.load(context, rawId, 3);
  17. }
  18. public void startSoundPool(float left, float right) {
  19. soundPool.play(1, left, right, 5, 0, 1);
  20. }
  21. public boolean soundComplete() {
  22. return isLoadComplete;
  23. }
  24. public void release() {
  25. soundPool.release();
  26. }
  27. }