Note that there are some explanatory texts on larger screens.

plurals
  1. POmultiple images multiple sounds issue android eclipse
    primarykey
    data
    text
    <p>I am fairly new to android eclipse and I am having a slight issue with an app I'm making. Basically I want to have 6 images, once you click on an image a set sound will play. The problem I'm having is no matter which image is clicked the same sound occurs. Below is my code for the activity, any help will be much appreciated. I have tried getting sound pools to work but I haven't find a good example to follow and not been able to get it to work.</p> <pre><code>package org.example.tuner; import android.app.Activity; import android.os.Bundle; import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; import android.widget.ImageView; import android.widget.RelativeLayout; import android.widget.TextView; import android.R.raw; import android.media.AudioManager; import android.media.MediaPlayer; import android.os.Bundle; import android.view.KeyEvent; public class GuitarTunerActivity extends Activity implements OnTouchListener { private MediaPlayer mp; ImageView estring, astring; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); setVolumeControlStream(AudioManager.STREAM_MUSIC); estring = (ImageView) findViewById(R.id.estring); estring.setOnTouchListener(this); astring = (ImageView) findViewById(R.id.astring); astring.setOnTouchListener(this); } public boolean onTouch(View v, MotionEvent event) { int resId; estring = (ImageView) findViewById(R.id.estring); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: resId = R.raw.e; System.out.println("Image is Touched"); break; default: return super.onTouchEvent(event); } if (mp != null) { mp.release(); } mp = MediaPlayer.create(this, resId); mp.start(); return true; } public boolean onTouch1(View v, MotionEvent event) { int resId; astring = (ImageView) findViewById(R.id.astring); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: resId = R.raw.a; System.out.println("Image is Touched"); break; default: return super.onTouchEvent(event); } if (mp != null) { mp.release(); } mp = MediaPlayer.create(this, resId); mp.start(); return true; } } </code></pre> <p>Please help me regarding this.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload