• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Android Multiple mp3 files on different button click not working

mini139

Newbie
I am trying to make an app that plays specific sounds on button click , I got like 400 buttons created statically not in an array or anything , and I assigned the sounds to each button correctly the problem is , after playing a number of buttons it gives me that error.

Anyway I could stop getting this error and the sounds to continue working on every button whatever the amount of sounds played??

The mp3 player is not loading and giving the error MediaPlayer error(-19,0)

Or is that possible to clear the clear data programatically. If so hw cum I tried clearing bt still the data is not getting cleares.

Is it like mediaplayer is crashing? If so what i have to do?

Java:
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_lesson9);
    addListenerOnButton();
    tts=new TextToSpeech(this,this);

    WebView wv=(WebView) findViewById(R.id.webView1);
    wv.getSettings().setPluginsEnabled(true);
    WebSettings webSettings = wv.getSettings();
    webSettings.setJavaScriptEnabled(true);
    wv.setBackgroundColor(Color.TRANSPARENT);

    WebView wv1=(WebView) findViewById(R.id.webView2);
    wv1.getSettings().setPluginsEnabled(true);
    WebSettings webSettings1 = wv1.getSettings();
    webSettings1.setJavaScriptEnabled(true);
    wv1.setBackgroundColor(Color.TRANSPARENT);

    WebView wv2=(WebView) findViewById(R.id.webView3);
    wv2.getSettings().setPluginsEnabled(true);
    WebSettings webSettings2 = wv2.getSettings();
    webSettings2.setJavaScriptEnabled(true);
    wv2.setBackgroundColor(Color.TRANSPARENT);


}
public void addListenerOnButton()
    {
    final Context context = this;
    final MediaPlayer mp,mp1,mp2,mp3,mp4,mp5,mp6,mp7,mp8,mp9,mp10,mp11;
    mp=MediaPlayer.create(this, R.raw.lla);
mp1=MediaPlayer.create(this, R.raw.ill);
mp2=MediaPlayer.create(this, R.raw.llaa);
mp3=MediaPlayer.create(this, R.raw.va);
mp5=MediaPlayer.create(this, R.raw.pazham);
mp6=MediaPlayer.create(this, R.raw.paazh);

button = (Button)findViewById(R.id.button1);
button1 = (Button)findViewById(R.id.button2);
button2 = (Button)findViewById(R.id.button3);
button3 = (Button)findViewById(R.id.button4);
button5 = (Button)findViewById(R.id.button6);
button6 = (Button)findViewById(R.id.button7);

txt = (TextView)findViewById(R.id.textView1);
txt1 = (TextView)findViewById(R.id.textView2);

button.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg) {
        WebView wv; 
    wv = (WebView) findViewById(R.id.webView1); 
    wv.loadUrl("file:///android_asset/www/lla.html");
    wv.setBackgroundColor(Color.TRANSPARENT);
    mp.start();
  }
});
button1.setOnClickListener(new OnClickListener()
{
  @Override
public void onClick(View arg) {
        WebView wv1; 
    wv1 = (WebView) findViewById(R.id.webView2); 
    wv1.loadUrl("file:///android_asset/www/ill.html");
    wv1.setBackgroundColor(Color.TRANSPARENT);
    mp1.start();
  }
});
button2.setOnClickListener(new OnClickListener()
{
  @Override
public void onClick(View arg) {
        WebView wv2; 
    wv2 = (WebView) findViewById(R.id.webView3); 
    wv2.loadUrl("file:///android_asset/www/llaa.html");
    wv2.setBackgroundColor(Color.TRANSPARENT);
    mp2.start();
  }
});
button3.setOnClickListener(new OnClickListener()
{
  @Override
public void onClick(View arg) {
        WebView wv3; 
    wv3 = (WebView) findViewById(R.id.webView4); 
    wv3.loadUrl("file:///android_asset/www/va.html");
    wv3.setBackgroundColor(Color.TRANSPARENT);
    mp3.start();
  }
});

button5.setOnClickListener(new OnClickListener()
{
    @Override
    public void onClick(View arg) {
    txt.setVisibility(View.VISIBLE);
    mp5.start();
}
});
button6.setOnClickListener(new OnClickListener()
{
  @Override
    public void onClick(View arg) {
    txt1.setVisibility(View.VISIBLE);
    mp6.start();
}
});
}
}

02-23 06:19:26.886: D/dalvikvm(975): GC_CONCURRENT freed 236K, 7% free 5060K/5440K, paused 12ms+115ms, total 677ms
02-23 06:19:27.046: W/PicturePileLayerContent(975): Warning: painting PicturePile without content!
02-23 06:19:27.046: W/PicturePileLayerContent(975): Warning: painting PicturePile without content!
02-23 06:19:27.246: W/PicturePileLayerContent(975): Warning: painting PicturePile without content!
02-23 06:19:27.646: W/PicturePileLayerContent(975): Warning: painting PicturePile without content!
02-23 06:19:27.816: W/PicturePileLayerContent(975): Warning: painting PicturePile without content!
02-23 06:19:28.155: W/PicturePileLayerContent(975): Warning: painting PicturePile without content!
02-23 06:19:28.185: W/PicturePileLayerContent(975): Warning: painting PicturePile without content!
02-23 06:19:28.196: W/PicturePileLayerContent(975): Warning: painting PicturePile without content!
02-23 06:19:28.326: E/MediaPlayer(975): error (-19, 0)
02-23 06:19:28.357: E/MediaPlayer(975): Error (-19,0)
02-23 06:19:28.476: W/PicturePileLayerContent(975): Warning: painting PicturePile without content!
02-23 06:19:28.476: W/PicturePileLayerContent(975): Warning: painting PicturePile without content!
02-23 06:19:28.509: W/PicturePileLayerContent(975): Warning: painting PicturePile without content!
02-23 06:19:28.676: W/PicturePileLayerContent(975): Warning: painting PicturePile without content!
02-23 06:19:28.696: W/PicturePileLayerContent(975): Warning: painting PicturePile without content!
02-23 06:19:28.856: W/PicturePileLayerContent(975): Warning: painting PicturePile without content!
02-23 06:19:28.866: W/PicturePileLayerContent(975): Warning: painting PicturePile without content!
 
Last edited:
There's some good advice for you here in this thread:

http://stackoverflow.com/questions/9888510/mediaplayer-error-19-0-after-repeated-plays

Basically you need to release your media players, similar to this example:

Code:
mp1 = MediaPlayer.create(sound.this, R.raw.pan1);
mp1.start();
mp1.setOnCompletionListener(new OnCompletionListener() {
   public void onCompletion(MediaPlayer mp) {
       mp.release();

   };
});

And BTW, you should consolidate all your separate button click listeners into one. You have a lot of duplicated code there.
 
Thanks for your help. Really that worked for me now. Now my app is working perfectly fine. Thanks again. A small request can u please explain the above code what it is doing? I understand that it is releasing the mediaplayer once the file is completed. If i am not releasing the previous file what will be happening there?
 
Back
Top Bottom