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

  • SEARCH
  • Home
  • 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 5929227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:23:40+00:00 2026-05-22T14:23:40+00:00

I am using the following code to play audio files continuously from a directory

  • 0

I am using the following code to play audio files continuously from a directory in sdcard.

The problem I am facing is all the files are playing at a time. I need to play one after another.

mPlay.setOnClickListener(new OnClickListener(){

            @Override
            public void onClick(View v) 
            {
                // TODO Auto-generated method stub
            getFiles();
            }

            private void getFiles() {
                // TODO Auto-generated method stub
                File dir = new File("/sdcard/sdcard");
                 int index=0;
                 String[] children = dir.list();
                 for(int i=0;i<children.length;i++)
                 {
                     String filename=children[i];
                     playAudio(filename);
                 }
            }

            private void playAudio(String filename) {
                // TODO Auto-generated method stub
                 mPlayer = new MediaPlayer();
                    try {
                        mPlayer.setDataSource(filename);
                    } catch (IllegalArgumentException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    } catch (IllegalStateException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    } catch (IOException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }
                    try {
                        mPlayer.prepare();
                    } catch (IllegalStateException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    } catch (IOException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }
                    mPlayer.start();
                    mSeekBar.setMax(mPlayer.getDuration());
                    new Thread(new Runnable(){

@Override
public void run() 
{
// TODO Auto-generated method stub
while(mPlayer!=null && mPlayer.getCurrentPosition() <mPlayer.getDuration())
    {
Log.d("Indide Run Method",Integer.toString(mPlayer.getCurrentPosition()));
    try 
    {
          Thread.sleep(100);
     } 
catch (InterruptedException e) 
    {
        // TODO Auto-generated catch block
        e.printStackTrace();
        }
                                mSeekBar.setProgress(mPlayer.getCurrentPosition());
                            }   


                        }

                    }
                    ).start();
                    mSeekBar.setProgress(mPlayer.getCurrentPosition());

        pauseRecord.setVisibility(View.INVISIBLE);  


            }

        });

How can solve the problem?

05-24 18:34:19.455: DEBUG/MediaPlayer(19961):     at dalvik.system.NativeStart.main(Native Method)
05-24 18:34:19.465: WARN/dalvikvm(19961): threadid=3: thread exiting with uncaught exception (group=0x2aadda10)
05-24 18:34:19.465: ERROR/AndroidRuntime(19961): Uncaught handler: thread main exiting due to uncaught exception
**05-24 18:34:19.465: ERROR/AndroidRuntime(19961): java.lang.NullPointerException
05-24 18:34:19.465: ERROR/AndroidRuntime(19961):     at com.fsp.audio.resume.AudioResume.playChild(AudioResume.java:402)
05-24 18:34:19.465: ERROR/AndroidRuntime(19961):     at com.fsp.audio.resume.AudioResume.playlist(AudioResume.java:393)
05-24 18:34:19.465: ERROR/AndroidRuntime(19961):     at com.fsp.audio.resume.AudioResume.access$0(AudioResume.java:391)
05-24 18:34:19.465: ERROR/AndroidRuntime(19961):     at com.fsp.audio.resume.AudioResume$1.onClick(AudioResume.java:132)
05-24 18:34:19.465: ERROR/AndroidRuntime(19961):     at android.view.View.performClick(View.java:2347)
05-24 18:34:19.465: ERROR/AndroidRuntime(19961):     at android.view.View.onTouchEvent(View.java:4185)
05-24 18:34:19.465: ERROR/AndroidRuntime(19961):     at android.widget.TextView.onTouchEvent(TextView.java:6521)
05-24 18:34:19.465: ERROR/AndroidRuntime(19961):     at android.view.View.dispatchTouchEvent(View.java:3717)**
05-24 18:34:19.465: ERROR/AndroidRuntime(19961):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
05-24 18:34:19.465: ERROR/AndroidRuntime(19961):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
05-24 18:34:19.465: ERROR/AndroidRuntime(19961):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
05-24 18:34:19.465: ERROR/AndroidRuntime(19961):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
05-24 18:34:19.465: ERROR/AndroidRuntime(19961):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
05-24 18:34:19.465: ERROR/AndroidRuntime(19961):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1712)
05-24 18:34:19.465: ERROR/AndroidRuntime(19961):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1202)
05-24 18:34:19.465: ERROR/AndroidRuntime(19961):     at android.app.Activity.dispatchTouchEvent(Activity.java:1987)
05-24 18:34:19.465: ERROR/AndroidRuntime(19961):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1696)
05-24 18:34:19.465: ERROR/AndroidRuntime(19961):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1659)
05-24 18:34:19.465: ERROR/AndroidRuntime(19961):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-24 18:34:19.465: ERROR/AndroidRuntime(19961):     at android.os.Looper.loop(Looper.java:123)
05-24 18:34:19.465: ERROR/AndroidRuntime(19961):     at android.app.ActivityThread.main(ActivityThread.java:4203)
05-24 18:34:19.465: ERROR/AndroidRuntime(19961):     at java.lang.reflect.Method.invokeNative(Native Method)
05-24 18:34:19.465: ERROR/AndroidRuntime(19961):     at java.lang.reflect.Method.invoke(Method.java:521)
05-24 18:34:19.465: ERROR/AndroidRuntime(19961):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:799)
05-24 18:34:19.465: ERROR/AndroidRuntime(19961):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
05-24 18:34:19.465: ERROR/AndroidRuntime(19961):     at dalvik.system.NativeStart.main(Native Method)
05-24 18:34:21.435: ERROR/dun_service(19989): Unable to open external port /dev/ttyHSUSB0 : No such device
05-24 18:34:26.465: ERROR/dun_service(19991): Unable to open external port /dev/ttyHSUSB0 : No such device
05-24 18:34:31.495: ERROR/dun_service(19993): Unable to open external port /dev/ttyHSUSB0 : No such device
05-24 18:34:36.525: ERROR/dun_service(19995): Unable to open external port /dev/ttyHSUSB0 : No such device
  • 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-05-22T14:23:40+00:00Added an answer on May 22, 2026 at 2:23 pm

    In order to play one file after the other you can use MediaPlayer.OnCompletionListener :

    final MediaPlayer mp1 = new MediaPlayer();
    mp1.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mp1.setDataSource(file1);
    mp1.prepare();
    mp1.start();
    
    mp1.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
        @Override
        public void onCompletion(MediaPlayer mp) {
            mp1.release();
            //file 1 has played, now play the second
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the following code to play audio file. I have tested the
I am using the following code to play the video. Actually it is playing
Hallo, I using the following code from css play. this display a menu. .preload16
I am using the following code, in the last line when I play the
Hey everyone. The following is the code that I am using to play random
I'm using following code but cannot return data from MySQL. This is the output:
Using the following code, I'm retrieving a list of Integers from a DB and
i am using the following code to play a sound when user touches anywhere
I am using the following code to play a sound file using the java
I am using the following code to play a wav file. I want the

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.