Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7734415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:14:38+00:00 2026-06-01T07:14:38+00:00

I have a problem with my soundboard app for android. When I test it

  • 0

I have a problem with my soundboard app for android.
When I test it on my device, the app crashes when I press the 8th ImageButton :.
Besides that I am wondering how I can stop the mediaplayer when I press another button.
Here is my code:

package nl.ingmar.soundboard;

import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;

import android.widget.ImageButton;

public class Main extends Activity implements OnClickListener {

ImageButton[] imagebuttons = new ImageButton[20];
MediaPlayer[] geluiden = new MediaPlayer[20];

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    init();
}

private void init() {

    for(int i=0; i<geluiden.length; i++){

        int rawID = getResources().getIdentifier( "geluid" + (i+1) , "raw" , getPackageName() );
        int resID = getResources().getIdentifier("btn" + (i+1), "id", getPackageName());  

        imagebuttons[i] = ((ImageButton) findViewById(resID));  
        imagebuttons[i].setOnClickListener(this); 

        geluiden[i] = MediaPlayer.create(this, rawID);
    }
}

@Override
public void onClick(View v) {
    int index = 0;
    for(int i = 0; i<imagebuttons.length; i++){
        if(imagebuttons[i].getId() == v.getId()){
            index = i;
            geluiden[i].start();
        }
    }
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T07:14:39+00:00Added an answer on June 1, 2026 at 7:14 am

    Using so many MediaPlayer instances is a bad idea. My guess is that creating these many instances is giving you the error.You are not releasing the mediaplayers you are using to play the sound by calling release() and you soon get out of memory. Call geluiden[i].release() on every instance when done.

    I would also like to tell you that MediaPlayer is not a good option when you are playing small sound effects as the user can click on multiple buttons very soon and you will have to create a MP object for all of them which doesnt happen synchronously. . Go for the SoundPool Class which allows you to keep smaller sounds loaded in memory and you can play them any time you want without any lag which you would feel in a mediaplayer. http://developer.android.com/reference/android/media/SoundPool.html Here is a nice tutorial : http://www.anddev.org/using_soundpool_instead_of_mediaplayer-t3115.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem running my app on Android 2.3 (Gingerbread). The app has a
I have problem in uploading .doc file to .Net WCF from my Android app.
I have problem in some JavaScript that I am writing where the Switch statement
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I have problem with fancybox. I want to write a function that will run
I am currently developing a soundboard for android and I have ran into a
I have problem while sending messages from android to PC. Messages are send when
I have problem with me51n. I have an include in EXIT_SAPLMEREQ_010 that has a
I have problem in Navigation Controller. I can't create dynamic buttons on Navigation Bar.
I have problem related with question I've set contentsScale and after that text looking

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.