Skip to content

Instantly share code, notes, and snippets.

@codeforfun-jp
Created June 10, 2021 00:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codeforfun-jp/280197b074ae4d175a301b5b9a43bb38 to your computer and use it in GitHub Desktop.
Save codeforfun-jp/280197b074ae4d175a301b5b9a43bb38 to your computer and use it in GitHub Desktop.
CTB 11-1
package jp.codeforfun.catchtheball;
import android.content.Context;
import android.media.AudioAttributes;
import android.media.AudioManager;
import android.media.SoundPool;
public class SoundPlayer {
private static SoundPool soundPool;
private static int hitSound;
private static int overSound;
public SoundPlayer(Context context) {
soundPool = new SoundPool(2, AudioManager.STREAM_MUSIC, 0);
hitSound = soundPool.load(context, R.raw.hit, 1);
overSound = soundPool.load(context, R.raw.over, 1);
}
public void playHitSound() {
soundPool.play(hitSound, 1.0f, 1.0f, 1, 0, 1.0f);
}
public void playOverSound() {
soundPool.play(overSound, 1.0f, 1.0f, 1, 0, 1.0f);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment