Have you checked the logcat view in Eclipse to see if there is any
error message there when it happens?

Just at a guess, it is all those MediaPlayer instances you have. You
may want to try only having one MediaPlayer, or a small pool of them.
Use new, setDataSource, and prepare instead of create. Use reset
before those when you want to reuse one for a different sound.

There's SoundPool too, but that has pretty tight limitations on the
size of the sound files.

On Mar 17, 4:52 pm, Gabriel <[email protected]> wrote:
> I'm having a really strange problem:
>
> I'm making a simple app with a lot of ImageButtons that make sounds
> when you click it.
>
> I've done that before, so I'm just copying a previous code for that
> and replacing the names and ids.
> But, after the 7th Button in the java code, the next ones "stop
> unexpectedly" in the emulator when I click them.
> From the first to the 7th it works perfectly, and after that they
> start to have problems.
>
> Apparently is not a code's problem, because when I just change the
> position between them, the ones that were not working start working
> and the ones that were normal, now stop working.
>
> I'm really trying to solve this, but I don't have any clue. I'm just
> copying the codes that are working right! And they become
> functionless.
>
> Here's the code: (note that the code is the same for all of them and
> only the last one, "eurotrip" is not working. The others are fine. If
> I just change the position eurotrip will work, but the other not.)
>
> package rosalan.cinema.sounds;
>
> import android.app.Activity;
> import android.media.MediaPlayer;
> import android.os.Bundle;
> import android.view.View;
> import android.view.Window;
> import android.view.WindowManager;
> import android.widget.ImageButton;
>
> public class Menuprovisorio extends Activity {
>
>         MediaPlayer ancora;
>         MediaPlayer aneis;
>         MediaPlayer jamesbond;
>         MediaPlayer borat;
>         MediaPlayer coringa;
>         MediaPlayer devolta;
>         MediaPlayer et;
>         MediaPlayer eurotrip;
>         MediaPlayer forrest;
>         MediaPlayer godf;
>         MediaPlayer hangover;
>         MediaPlayer hg;
>         MediaPlayer iluminado;
>         MediaPlayer kill;
>         MediaPlayer laranja;
>         MediaPlayer old;
>         MediaPlayer poderoso;
>         MediaPlayer psico;
>         MediaPlayer pulp;
>         MediaPlayer scarface;
>         MediaPlayer sparta;
>         MediaPlayer spider;
>         MediaPlayer starw;
>         MediaPlayer terminator;
>         MediaPlayer toy;
>         MediaPlayer v;
>         MediaPlayer vaderoutro;
>
>         ImageButton a1;
>         ImageButton a2;
>         ImageButton a3;
>         ImageButton a4;
>         ImageButton a5;
>         ImageButton a6;
>
>         ImageButton a8;
>         ImageButton a9;
>         ImageButton b1;
>         ImageButton b2;
>         ImageButton b3;
>         ImageButton b4;
>         ImageButton b5;
>         ImageButton b6;
>         ImageButton b7;
>         ImageButton b8;
>         ImageButton b9;
>         ImageButton c1;
>         ImageButton c2;
>         ImageButton c3;
>         ImageButton c4;
>         ImageButton c5;
>         ImageButton c6;
>         ImageButton c7;
>         ImageButton c8;
>         ImageButton c9;
>         ImageButton a7;
>
>         @Override
>         protected void onCreate(Bundle savedInstanceState) {
>                 // TODO Auto-generated method stub
>                 super.onCreate(savedInstanceState);
>                 requestWindowFeature(Window.FEATURE_NO_TITLE);
>                 
> getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
> WindowManager.LayoutParams.FLAG_FULLSCREEN);
>                 setContentView(R.layout.main);
>
>                 vaderoutro = MediaPlayer.create(this, R.raw.breath);
>
>                  a8 = (ImageButton) findViewById(R.id.a8);
>                  a8.setOnClickListener(new View.OnClickListener() {
>
>                                 @Override
>                                 public void onClick(View v) {
>                                         // TODO Auto-generated method stub
>
>                                         vaderoutro.start();
>                                 }
>                         });
>                  pulp = MediaPlayer.create(this, R.raw.pulp);
>
>                  a9 = (ImageButton) findViewById(R.id.a9);
>                  a9.setOnClickListener(new View.OnClickListener() {
>
>                                 @Override
>                                 public void onClick(View v) {
>                                         // TODO Auto-generated method stub
>
>                                         pulp.start();
>                                 }
>                         });
>
>                         jamesbond = MediaPlayer.create(this, R.raw.bond);
>
>                         a1 = (ImageButton) findViewById(R.id.a1);
>                         a1.setOnClickListener(new View.OnClickListener() {
>
>                                 @Override
>                                 public void onClick(View v) {
>                                         // TODO Auto-generated method stub
>
>                                         jamesbond.start();
>                                 }
>                         });
>
>                         scarface = MediaPlayer.create(this, R.raw.scarface);
>
>                         a2 = (ImageButton) findViewById(R.id.a2);
>                         a2.setOnClickListener(new View.OnClickListener() {
>
>                                 @Override
>                                 public void onClick(View v) {
>                                         // TODO Auto-generated method stub
>
>                                         scarface.start();
>                                 }
>                         });
>                  kill = MediaPlayer.create(this, R.raw.kill);
>
>                  a4 = (ImageButton) findViewById(R.id.a4);
>                  a4.setOnClickListener(new View.OnClickListener() {
>
>                                 @Override
>                                 public void onClick(View v) {
>                                         // TODO Auto-generated method stub
>
>                                         kill.start();
>                                 }
>                         });
>
>                         aneis = MediaPlayer.create(this, R.raw.aneis);
>
>                         a5 = (ImageButton) findViewById(R.id.a5);
>                         a5.setOnClickListener(new View.OnClickListener() {
>
>                                 @Override
>                                 public void onClick(View v) {
>                                         // TODO Auto-generated method stub
>
>                                         aneis.start();
>                                 }
>                         });
>
>                         coringa = MediaPlayer.create(this, R.raw.coringa);
>
>                         a6 = (ImageButton) findViewById(R.id.a6);
>                         a6.setOnClickListener(new View.OnClickListener() {
>
>                                 @Override
>                                 public void onClick(View v) {
>                                         // TODO Auto-generated method stub
>
>                                         coringa.start();
>                                 }
>                         });
>
>                         eurotrip = MediaPlayer.create(this, R.raw.eurotrip);
>
>                         a7 = (ImageButton) findViewById(R.id.a7);
>                         a7.setOnClickListener(new View.OnClickListener() {
>
>                                 @Override
>                                 public void onClick(View v) {
>
>                                         eurotrip.start();
>                                 }
>                         });

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

Reply via email to