error playing audio file when the8th times

All your problems with Audio, Video and Images.

error playing audio file when the8th times

Postby eckops » Thu May 20, 2010 8:01 pm

Hi all...i'm a newbee in android...
i have one strange problem in multimedia...

in my coding, if i click a button, will play the audio file from the raw folder...i can hear the audio sound when i click the button...but, when i click the button at the 8th times, is error, not worked...

anyone can help me??please....

this my code :
slidebuah.java
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. import android.app.Activity;
  2. import android.app.AlertDialog;
  3. import android.content.DialogInterface;
  4. import android.media.MediaPlayer;
  5. import android.os.Bundle;  
  6. import android.view.View;
  7. import android.view.View.OnClickListener;
  8. import android.widget.Button;
  9. import android.widget.ImageView;  
  10. import android.widget.TextView;
  11.  
  12. public class slidebuah extends Activity implements OnClickListener {
  13.     private DBhelper DbHelper;
  14.     private int temp =1;
  15.     private String myMessage, title;
  16.     MediaPlayer MPX ;
  17.     public void onCreate(Bundle savedInstanceState) {
  18.         super.onCreate(savedInstanceState);
  19.         setContentView(R.layout.tampilanslide);
  20.         ImageView tampilgambarbuah = (ImageView)this.findViewById(R.id.gambar);
  21.         TextView textindobuah = (TextView) this.findViewById(R.id.textindo);
  22.         TextView textenglishbuah = (TextView) this.findViewById(R.id.textenglish);
  23.        
  24.         Button kemenu = (Button) this.findViewById(R.id.tombolkemenu);
  25.                         kemenu.setOnClickListener(this);
  26.         Button next = (Button) this.findViewById(R.id.tombolnext);
  27.                         next.setOnClickListener(this); 
  28.                          Button back = (Button) this.findViewById(R.id.tombolback);
  29.                         back.setOnClickListener(this);
  30.        
  31.         DbHelper = new DBhelper(this);
  32.        
  33.         DbHelper.open();
  34.         int rowId = 1;
  35.         Object testFruit = DbHelper.getFirstFruitFromDB(rowId);
  36.         DbHelper.close();
  37.        
  38.         tampilgambarbuah.setImageResource(testFruit.getBitmap());
  39.         textindobuah.setText(testFruit.getName());
  40.         textenglishbuah.setText(testFruit.getEnglish());  
  41.     }
  42.  
  43.     public void output(Object nextFruits){
  44.         ImageView tampilgambarbuah = (ImageView)this.findViewById(R.id.gambar);
  45.         TextView textindobuah = (TextView) this.findViewById(R.id.textindo);
  46.         TextView textenglishbuah = (TextView) this.findViewById(R.id.textenglish);
  47.         tampilgambarbuah.setImageResource(nextFruits.getBitmap());
  48.         textindobuah.setText(nextFruits.getName());
  49.         textenglishbuah.setText(nextFruits.getEnglish());
  50.     }
  51.    
  52.    
  53.  
  54.     public void onClick(View v) {
  55.    
  56.         switch (v.getId()) {
  57.        
  58.            
  59.         case R.id.tombolkemenu:
  60.                 bunyiclick();
  61.            slidebuah.this.finish();
  62.            break;
  63.              
  64.         case R.id.tombolnext:
  65.                 bunyiclick();
  66.                  DbHelper.open();
  67.                  Object nextFruits = DbHelper.getFirstFruitFromDB(temp + 1);
  68.                         DbHelper.close();
  69.                 if(nextFruits!= null){
  70.                         output(nextFruits);
  71.                         temp =  temp+1;
  72.                 }
  73.                 else{
  74.                        
  75.                         title= "Pemberitahuan";
  76.                                 myMessage = "Maaf, ini adalah objek buah yang terakhir.";
  77.                                 alertbox(title,myMessage);;
  78.                 }
  79.                
  80.            break;
  81.            
  82.         case R.id.tombolback:
  83.                 bunyiclick();
  84.                  DbHelper.open();
  85.                  Object backFruits = DbHelper.getFirstFruitFromDB(temp - 1);
  86.                         DbHelper.close();
  87.                 if(backFruits!= null){
  88.                         output(backFruits);
  89.                 temp = temp -1;
  90.                 }
  91.                 else{
  92.                         bunyierror();
  93.                         title= "Pemberitahuan";
  94.                                 myMessage = "Maaf, ini adalah objek buah yang pertama.";
  95.                                 alertbox(title,myMessage);}
  96.            break;
  97.             }
  98.        
  99.                 }
  100.     protected void alertbox(String title, String mymessage)  
  101.     {  
  102.     new AlertDialog.Builder(this)  
  103.        .setMessage(mymessage)  
  104.        .setTitle(title)  
  105.        .setCancelable(true)  
  106.        .setNeutralButton(android.R.string.ok,  
  107.           new DialogInterface.OnClickListener() {  
  108.           public void onClick(DialogInterface dialog, int whichButton){}  
  109.           })  
  110.        .show();  
  111.     }  
  112.     public void bunyiclick(){MediaPlayer mp = MediaPlayer.create(slidebuah.this,
  113.             R.raw.a);
  114.     mp.start();}
  115.     public void bunyierror(){MediaPlayer mp = MediaPlayer.create(slidebuah.this,
  116.             R.raw.error);
  117.     mp.start();}
  118.  
  119. }
  120.  
Parsed in 0.047 seconds, using GeSHi 1.0.8.4



object.java
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class Object {
  2.     private int bmp;
  3.     private String name;
  4.     private String english;
  5.  
  6.     public Object( int b, String n, String k) {
  7.         bmp = b;
  8.         name = n;
  9.         english = k;
  10.  
  11.     }
  12.    
  13.     public int getBitmap() { return bmp; }
  14.     public String getName() { return name; }
  15.     public String getEnglish() { return english; }
  16. }
  17.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4





sorry for my english...
eckops
Junior Developer
Junior Developer
 
Posts: 11
Joined: Sun Mar 21, 2010 7:41 am

Top

Re: error playing audio file when the8th times

Postby uncre8d1 » Wed Jun 09, 2010 8:27 pm

I had the same issue; you have to set an onCompletionListener for your MediaPlayer. In the listener, you need to have the statement 'mp.reset();' This will reset the mediaplayer to its basic initialized state. Not sure why the 8th time crashes it but I think it has to do with device RAM running out.
Normal?!? Man, I'd give my left arms to be normal.
User avatar
uncre8d1
Junior Developer
Junior Developer
 
Posts: 18
Joined: Tue Mar 16, 2010 3:41 am
Location: Silver Spring, MD

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 16 guests