Advertisement
mmayoub

MySoundPool.java

Feb 24th, 2023
826
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.41 KB | Software | 0 0
  1. package com.example.mygame15board;
  2.  
  3. import android.content.Context;
  4. import android.media.AudioAttributes;
  5. import android.media.SoundPool;
  6.  
  7. public class MySoundPool {
  8.     private Context context;
  9.     private SoundPool soundPool;
  10.  
  11.     private int clickOkSoundId;
  12.     private int clickErrorSoundId;
  13.  
  14.     private int gameOverSoundId;
  15.  
  16.     public MySoundPool(Context context) {
  17.         this.context = context;
  18.         AudioAttributes audioAttributes = new AudioAttributes
  19.                 .Builder()
  20.                 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
  21.                 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
  22.                 .build();
  23.         soundPool = new SoundPool
  24.                 .Builder()
  25.                 .setMaxStreams(3)
  26.                 .setAudioAttributes(audioAttributes)
  27.                 .build();
  28.         clickOkSoundId = soundPool.load(context, R.raw.click, 1);
  29.         clickErrorSoundId = soundPool.load(context, R.raw.error, 1);
  30.         gameOverSoundId = soundPool.load(context, R.raw.over, 1);
  31.     }
  32.  
  33.     public void playClickOk() {
  34.         soundPool.play(
  35.                 clickOkSoundId, 1, 1, 0, 0, 1);
  36.     }
  37.  
  38.     public void playClickError() {
  39.         soundPool.play(
  40.                 clickErrorSoundId, 1, 1, 0, 0, 1);
  41.     }
  42.  
  43.     public void playGameOver() {
  44.         soundPool.play(
  45.                 gameOverSoundId, 1, 1, 0, 0, 1);
  46.     }
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement