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 7404479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:15:43+00:00 2026-05-29T05:15:43+00:00

Hi guys i am having 3 audio files and three images with three text

  • 0

Hi guys i am having 3 audio files and three images with three text displaying for each image.
Now what i have done as soon as application starts the first image,text and audio file starts playing and after completion of that 2nd one starts similarly 3rd one starts.

Basically i need these to played sequentially one after the other but dynamically since i am having some 20 files similar to this

below is my code

public class S001Activity extends Activity {
    /** Called when the activity is first created. */

    ImageView img;
    TextView display;
    MediaPlayer apple = new MediaPlayer();
    MediaPlayer boy = new MediaPlayer();
    MediaPlayer cat = new MediaPlayer();
    //Runnable rb,rc;

    Document doc;
    DocumentBuilder builder;
    Handler handler = new Handler();

    int i=0;
    int noOfQues = 0;
    //int media[] = {R.raw.apple_v,R.raw.boy_v,R.raw.cat_v};
    //int image[] = {R.drawable.apple,R.drawable.boy,R.drawable.cat};

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

        img = (ImageView)findViewById(R.id.img);
        display = (TextView)findViewById(R.id.display);

        img.setBackgroundResource(R.drawable.apple);
        apple = MediaPlayer.create(this, R.raw.apple_v);
        apple.start();
        xml();


        boy = MediaPlayer.create(this, R.raw.boy_v);

        handler.postDelayed(new Runnable() {

            @Override
            public void run() {
                // TODO Auto-generated method stub
                i++;
                img.setBackgroundResource(R.drawable.boy);

                boy.start();
                xml();
            }
        },apple.getDuration()+ 2000 );

        cat = MediaPlayer.create(this, R.raw.cat_v);
            handler.postDelayed(new Runnable() {

            @Override
            public void run() {
                // TODO Auto-generated method stub
                i++;
                img.setBackgroundResource(R.drawable.cat);
                cat.start();
                xml();
            }
        },apple.getDuration()+ boy.getDuration()+ 2000 );
}


    public void xml(){
         try {
            InputStream in = getResources().openRawResource(R.raw.topic1761);
            builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
            doc = builder.parse(in, null);

            NodeList listOfPersons = doc.getElementsByTagName("Point");
            noOfQues = listOfPersons.getLength();
            System.out.println("items======= " + noOfQues);

            Node firstPersonNode = listOfPersons.item(i);

            Element firstPersonElement = (Element) firstPersonNode;

            NodeList firstNameList = firstPersonElement.getElementsByTagName("PracticeText");
            Element firstNameElement = (Element) firstNameList.item(0);

            NodeList textFNList = firstNameElement.getChildNodes();
            display.setText(((Node) textFNList.item(0)).getNodeValue().trim());

        } catch (Throwable t) {
            Toast.makeText(this, "Exception: " + t.toString(), 2000).show();
        }
    }

edited code

@Override
    public void onCompletion(MediaPlayer mps) {
        // TODO Auto-generated method stub
        //MediaPlayer mps = new MediaPlayer();

        img.setBackgroundResource(image[i]);
        handler.post(new Runnable() {

              @Override
              public void run() {

                  xml();
                  AssetFileDescriptor afd = getResources().openRawResourceFd(media[i]);
                  mp.reset();
                  try {
                    mp.setDataSource(afd.getFileDescriptor());
                    afd.close();
                    mp.prepare();
                    mp.start();

                } catch (IllegalArgumentException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IllegalStateException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

              }
             });  
    }
  • 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-29T05:15:44+00:00Added an answer on May 29, 2026 at 5:15 am

    You can use array or a list to store the list of music files, image files and text.
    Then play the next one in MediaPlayer.OnCompletionListener.

    EDIT:

    int media[] = {R.raw.apple_v,R.raw.boy_v,R.raw.cat_v};
    MediaPlayer mp = new MediaPlayer();
    
    // in OnCompletionListener,
    index = index + 1; //add proper checks
    handler.post(new Runnable() {
    
      @Override
      public void run() {
          AssetFileDescriptor afd = getResources().openRawResourceFd(media[index]);
          mp.reset();
          mp.setDataSource(afd.getFileDescriptor());
          afd.close();
          mp.prepare();
          mp.start();
      }
     });  
    

    I think you can get the idea with the above sample code.

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

Sidebar

Related Questions

I am struggling with a problem that In my application Im having audio files
YO guys, Im having a problem with my app. I have Splash screen images
hey guys having this really simple problem but cant seem to figure out have
guys am having some troubles with running out of memory when displaying an animation
Hey guys am having a bit of problems with my jQuery, I have all
right guys im having trouble with one. what i want to do is have
Hi guys I am having issue I have this query: SELECT * FROM useraccount
Hey guys I'm having such a hard time of it today. I have a
Hey guys, I was wondering if it were possible to translate audio without having
guys i am having a text like this: A: hi how are you. B:

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.