Tuesday, March 20, 2012

[android-developers] Media Player problem


hi guys,

i'am a beginner in development, 
and i'am developing an app which i'm using ImageView and the image when it's clicked should play a sound for 6 sec, so i used MediaPlayer i start it inside the (switch case)
all woks good, but the problem is when i click  on the same imageview the sound will start inside the old one!!is there any way to handle the imageview or the screen till the sound is finish, also if i click the second image the sound will come together.

this is a part of my code which may help to explain the problem:
 
ImageView display
@Override
protected void onCreate(Bundle savedInstanceState) 
{
super.onCreate(savedInstanceState);
setContentView(R.layout.alphabets_menu);
display = (ImageView) findViewById (R.id.main_view);
MediaPlayer image_sound
image_a = (ImageView) findViewById (R.id.image_a);

image_a.setOnClickListener(this);

public void onClick(View v) 
{
// TODO Auto-generated method stub
image_sound = MediaPlayer.create(this, R.raw.image_s);
}


switch (v.getId())
{
case R.id.image_a:
display.setImageResource(R.drawable.a);
image_sound.start();
break;
}





thanks...

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment