Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- How do you use an iterator to cycle through multiple sound clips every time you click a button?
- package com.pnl.thebasics;
- import java.util.HashMap;
- import java.util.Random;
- import android.app.Activity;
- import android.media.AudioManager;
- import android.media.SoundPool;
- import android.os.Bundle;
- import android.view.View;
- import android.view.Window;
- import android.view.WindowManager;
- import android.widget.ImageView;
- public class myMenu extends Activity {
- private SoundPool soundPool;
- private HashMap<Integer, Integer> soundsMap;
- int sb1=1;
- int sb2=2;
- int sb3=3;
- int sb4=4;
- int sb5=5;
- int sb6=6;
- int pat1=1;
- int pat2=2;
- int pat3=3;
- int pat4=4;
- int pat5=5;
- int pat6=6;
- int mrcrabs1=1;
- int mrcrabs2=2;
- int mrcrabs3=3;
- int mrcrabs4=4;
- int mrcrabs5=5;
- int squidward1=1;
- int squidward2=2;
- int squidward3=3;
- int squidward4=4;
- int squidward5=5;
- int plankton1=1;
- int plankton2=2;
- int plankton3=3;
- int plankton4=4;
- int plankton5=5;
- int gary1=1;
- int gary2=2;
- int gary3=3;
- int gary4=4;
- Random random = new Random();
- int randomnumber = random.nextInt(6)+1;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- requestWindowFeature(Window.FEATURE_NO_TITLE);
- final Window window = getWindow();
- window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
- soundPool = new SoundPool(0, AudioManager.STREAM_MUSIC, 100);
- soundsMap = new HashMap<Integer, Integer>();
- soundsMap.put(sb1, soundPool.load(this, R.raw.sb1, 1));
- soundsMap.put(sb2, soundPool.load(this, R.raw.sb2, 1));
- soundsMap.put(sb3, soundPool.load(this, R.raw.sb3, 1));
- soundsMap.put(sb4, soundPool.load(this, R.raw.sb4, 1));
- soundsMap.put(sb5, soundPool.load(this, R.raw.sb5, 1));
- soundsMap.put(sb6, soundPool.load(this, R.raw.sb6, 1));
- soundsMap.put(pat1, soundPool.load(this, R.raw.pat1, 1));
- soundsMap.put(pat2, soundPool.load(this, R.raw.pat2, 1));
- soundsMap.put(pat3, soundPool.load(this, R.raw.pat3, 1));
- soundsMap.put(pat4, soundPool.load(this, R.raw.pat4, 1));
- soundsMap.put(pat5, soundPool.load(this, R.raw.pat5, 1));
- soundsMap.put(pat6, soundPool.load(this, R.raw.pat6, 1));
- soundsMap.put(mrcrabs1, soundPool.load(this, R.raw.mrcrabs1, 1));
- soundsMap.put(mrcrabs2, soundPool.load(this, R.raw.mrcrabs2, 1));
- soundsMap.put(mrcrabs3, soundPool.load(this, R.raw.mrcrabs3, 1));
- soundsMap.put(mrcrabs4, soundPool.load(this, R.raw.mrcrabs4, 1));
- soundsMap.put(mrcrabs5, soundPool.load(this, R.raw.mrcrabs5, 1));
- soundsMap.put(squidward1, soundPool.load(this, R.raw.squidward1, 1));
- soundsMap.put(squidward2, soundPool.load(this, R.raw.squidward2, 1));
- soundsMap.put(squidward3, soundPool.load(this, R.raw.squidward3, 1));
- soundsMap.put(squidward4, soundPool.load(this, R.raw.squidward4, 1));
- soundsMap.put(squidward5, soundPool.load(this, R.raw.squidward5, 1));
- soundsMap.put(plankton1, soundPool.load(this, R.raw.plankton1, 1));
- soundsMap.put(plankton2, soundPool.load(this, R.raw.plankton2, 1));
- soundsMap.put(plankton3, soundPool.load(this, R.raw.plankton3, 1));
- soundsMap.put(plankton4, soundPool.load(this, R.raw.plankton4, 1));
- soundsMap.put(plankton5, soundPool.load(this, R.raw.plankton5, 1));
- soundsMap.put(gary1, soundPool.load(this, R.raw.gary1, 1));
- soundsMap.put(gary2, soundPool.load(this, R.raw.gary2, 1));
- soundsMap.put(gary3, soundPool.load(this, R.raw.gary3, 1));
- soundsMap.put(gary4, soundPool.load(this, R.raw.gary4, 1));
- setContentView(R.layout.menu);
- //button 1 (sponge bob)
- ImageView bSpongebob = (ImageView) findViewById(R.id.sbbutton);
- bSpongebob.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- // TODO Auto-generated method stub
- }
- });
- //button 2 (patrick)
- ImageView bPatrick = (ImageView) findViewById(R.id.patbutton);
- bPatrick.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- // TODO Auto-generated method stub
- }
- });
- //button 3 (squidward)
- ImageView bSquidward = (ImageView) findViewById(R.id.squidwardbutton);
- bSquidward.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- // TODO Auto-generated method stub
- }
- });
- //button 4 (mr crabs)
- ImageView bMrCrabs = (ImageView) findViewById(R.id.mrcrabsbutton);
- bMrCrabs.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- // TODO Auto-generated method stub
- }
- });
- //button 5 (gary)
- ImageView bGary = (ImageView) findViewById(R.id.garybutton);
- bGary.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- // TODO Auto-generated method stub
- }
- });
- //button 6 (plankton)
- ImageView bPlankton = (ImageView) findViewById(R.id.planktonbutton);
- bPlankton.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- // TODO Auto-generated method stub
- }
- });
- }
- }
Add Comment
Please, Sign In to add comment