FAQS


How to start media or sound file.

Views: 1748  |   Date: 2013-08-16 07:40:25

How to start media file in android program.

Answer 1

Use this code to start media file.

  
  MediaPlayer mp = MediaPlayer.create(context,R.raw.audio);
  mp.start(); 

Answer 2

To prevent ANR problem try to start media inside worker thread.

  
Thread workerThread = new Thread(new Runnable() {
  public void run() {
  try {
           MediaPlayer mp = MediaPlayer.create(context,R.raw.audio);
           mp.start();
      } 
     catch (Throwable t) {
     Log.i("StartMediaFile", "Thread  exception "+t);
  }   
     }
 });
 
 workerThread.start();
 

 
Submit Your Answer
  |  
 
 
 

Preview :