Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.mygame15board;
- import android.content.Context;
- import android.media.AudioAttributes;
- import android.media.SoundPool;
- public class MySoundPool {
- private Context context;
- private SoundPool soundPool;
- private int clickOkSoundId;
- private int clickErrorSoundId;
- private int gameOverSoundId;
- public MySoundPool(Context context) {
- this.context = context;
- AudioAttributes audioAttributes = new AudioAttributes
- .Builder()
- .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
- .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
- .build();
- soundPool = new SoundPool
- .Builder()
- .setMaxStreams(3)
- .setAudioAttributes(audioAttributes)
- .build();
- clickOkSoundId = soundPool.load(context, R.raw.click, 1);
- clickErrorSoundId = soundPool.load(context, R.raw.error, 1);
- gameOverSoundId = soundPool.load(context, R.raw.over, 1);
- }
- public void playClickOk() {
- soundPool.play(
- clickOkSoundId, 1, 1, 0, 0, 1);
- }
- public void playClickError() {
- soundPool.play(
- clickErrorSoundId, 1, 1, 0, 0, 1);
- }
- public void playGameOver() {
- soundPool.play(
- gameOverSoundId, 1, 1, 0, 0, 1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement