daily pastebin goal
67%
SHARE
TWEET

Untitled

a guest Aug 15th, 2018 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. How do you use an iterator to cycle through multiple sound clips every time you click a button?
  2. package com.pnl.thebasics;
  3.  
  4. import java.util.HashMap;
  5. import java.util.Random;
  6.  
  7. import android.app.Activity;
  8. import android.media.AudioManager;
  9. import android.media.SoundPool;
  10. import android.os.Bundle;
  11. import android.view.View;
  12. import android.view.Window;
  13. import android.view.WindowManager;
  14. import android.widget.ImageView;
  15.  
  16. public class myMenu extends Activity {
  17.  
  18. private SoundPool soundPool;
  19. private HashMap<Integer, Integer> soundsMap;
  20. int sb1=1;
  21. int sb2=2;
  22. int sb3=3;
  23. int sb4=4;
  24. int sb5=5;
  25. int sb6=6;
  26. int pat1=1;
  27. int pat2=2;
  28. int pat3=3;
  29. int pat4=4;
  30. int pat5=5;
  31. int pat6=6;
  32. int mrcrabs1=1;
  33. int mrcrabs2=2;
  34. int mrcrabs3=3;
  35. int mrcrabs4=4;
  36. int mrcrabs5=5;
  37. int squidward1=1;
  38. int squidward2=2;
  39. int squidward3=3;
  40. int squidward4=4;
  41. int squidward5=5;
  42. int plankton1=1;
  43. int plankton2=2;
  44. int plankton3=3;
  45. int plankton4=4;
  46. int plankton5=5;
  47. int gary1=1;
  48. int gary2=2;
  49. int gary3=3;
  50. int gary4=4;
  51.  
  52. Random random = new Random();
  53. int randomnumber = random.nextInt(6)+1;
  54.  
  55.  
  56. @Override
  57. protected void onCreate(Bundle savedInstanceState) {
  58.     super.onCreate(savedInstanceState);
  59.     requestWindowFeature(Window.FEATURE_NO_TITLE);
  60.     final Window window = getWindow();
  61.     window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,                WindowManager.LayoutParams.FLAG_FULLSCREEN);
  62.     soundPool = new SoundPool(0, AudioManager.STREAM_MUSIC, 100);
  63.     soundsMap = new HashMap<Integer, Integer>();
  64.     soundsMap.put(sb1, soundPool.load(this, R.raw.sb1, 1));
  65.     soundsMap.put(sb2, soundPool.load(this, R.raw.sb2, 1));
  66.     soundsMap.put(sb3, soundPool.load(this, R.raw.sb3, 1));
  67.     soundsMap.put(sb4, soundPool.load(this, R.raw.sb4, 1));
  68.     soundsMap.put(sb5, soundPool.load(this, R.raw.sb5, 1));
  69.     soundsMap.put(sb6, soundPool.load(this, R.raw.sb6, 1));
  70.     soundsMap.put(pat1, soundPool.load(this, R.raw.pat1, 1));
  71.     soundsMap.put(pat2, soundPool.load(this, R.raw.pat2, 1));
  72.     soundsMap.put(pat3, soundPool.load(this, R.raw.pat3, 1));
  73.     soundsMap.put(pat4, soundPool.load(this, R.raw.pat4, 1));
  74.     soundsMap.put(pat5, soundPool.load(this, R.raw.pat5, 1));
  75.     soundsMap.put(pat6, soundPool.load(this, R.raw.pat6, 1));
  76.     soundsMap.put(mrcrabs1, soundPool.load(this, R.raw.mrcrabs1, 1));
  77.     soundsMap.put(mrcrabs2, soundPool.load(this, R.raw.mrcrabs2, 1));
  78.     soundsMap.put(mrcrabs3, soundPool.load(this, R.raw.mrcrabs3, 1));
  79.     soundsMap.put(mrcrabs4, soundPool.load(this, R.raw.mrcrabs4, 1));
  80.     soundsMap.put(mrcrabs5, soundPool.load(this, R.raw.mrcrabs5, 1));
  81.     soundsMap.put(squidward1, soundPool.load(this, R.raw.squidward1, 1));
  82.     soundsMap.put(squidward2, soundPool.load(this, R.raw.squidward2, 1));
  83.     soundsMap.put(squidward3, soundPool.load(this, R.raw.squidward3, 1));
  84.     soundsMap.put(squidward4, soundPool.load(this, R.raw.squidward4, 1));
  85.     soundsMap.put(squidward5, soundPool.load(this, R.raw.squidward5, 1));
  86.     soundsMap.put(plankton1, soundPool.load(this, R.raw.plankton1, 1));
  87.     soundsMap.put(plankton2, soundPool.load(this, R.raw.plankton2, 1));
  88.     soundsMap.put(plankton3, soundPool.load(this, R.raw.plankton3, 1));
  89.     soundsMap.put(plankton4, soundPool.load(this, R.raw.plankton4, 1));
  90.     soundsMap.put(plankton5, soundPool.load(this, R.raw.plankton5, 1));
  91.     soundsMap.put(gary1, soundPool.load(this, R.raw.gary1, 1));
  92.     soundsMap.put(gary2, soundPool.load(this, R.raw.gary2, 1));
  93.     soundsMap.put(gary3, soundPool.load(this, R.raw.gary3, 1));
  94.     soundsMap.put(gary4, soundPool.load(this, R.raw.gary4, 1));
  95.  
  96.     setContentView(R.layout.menu);
  97.  
  98.     //button 1 (sponge bob)
  99.     ImageView bSpongebob = (ImageView) findViewById(R.id.sbbutton);
  100.     bSpongebob.setOnClickListener(new View.OnClickListener() {
  101.  
  102.         public void onClick(View v) {
  103.             // TODO Auto-generated method stub
  104.  
  105.         }
  106.     });
  107.  
  108.     //button 2 (patrick)
  109.     ImageView bPatrick = (ImageView) findViewById(R.id.patbutton);
  110.     bPatrick.setOnClickListener(new View.OnClickListener() {
  111.  
  112.         public void onClick(View v) {
  113.             // TODO Auto-generated method stub
  114.  
  115.         }
  116.     });
  117.  
  118.     //button 3 (squidward)
  119.     ImageView bSquidward = (ImageView) findViewById(R.id.squidwardbutton);
  120.     bSquidward.setOnClickListener(new View.OnClickListener() {
  121.  
  122.         public void onClick(View v) {
  123.             // TODO Auto-generated method stub
  124.  
  125.         }
  126.     });
  127.  
  128.     //button 4 (mr crabs)
  129.     ImageView bMrCrabs = (ImageView) findViewById(R.id.mrcrabsbutton);
  130.     bMrCrabs.setOnClickListener(new View.OnClickListener() {
  131.  
  132.         public void onClick(View v) {
  133.             // TODO Auto-generated method stub
  134.  
  135.         }
  136.     });
  137.  
  138.     //button 5 (gary)
  139.     ImageView bGary = (ImageView) findViewById(R.id.garybutton);
  140.     bGary.setOnClickListener(new View.OnClickListener() {
  141.  
  142.         public void onClick(View v) {
  143.             // TODO Auto-generated method stub
  144.  
  145.         }
  146.     });
  147.  
  148.     //button 6 (plankton)
  149.     ImageView bPlankton = (ImageView) findViewById(R.id.planktonbutton);
  150.     bPlankton.setOnClickListener(new View.OnClickListener() {
  151.  
  152.         public void onClick(View v) {
  153.             // TODO Auto-generated method stub
  154.  
  155.         }
  156.     });
  157. }
  158. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top