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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:46:11+00:00 2026-05-27T17:46:11+00:00

I am developing in Android and have been trying to create an Async task

  • 0

I am developing in Android and have been trying to create an Async task that plays audio files in order depending on a set of boolean values (if i1 is true, then it plays i1, and then when i1 is done, if i2 is true it plays that and so on). My first attempt is not crashing the app, but is also not playing the audio file.

    class SessionMusicTask extends AsyncTask<Void, Void, Void>{

        @Override
        protected Void doInBackground(Void... params) {
            try {
                while(playing == true){
                if(i1 == true && done == true){
                    done = false;
                    player.setDataSource(i1Loc);
                    player.prepare();
                    player.start();
                    player.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {

                        public void onCompletion(MediaPlayer mp) {
                            done = true;

                        }
                    });
                }
                }
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            } catch (IllegalStateException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            super.onPostExecute(result);
        }

    }

Is this the best approach to the problem? Any idea why the file isn’t playing?
Thanks for any help in advance.

Update:
I just put a finish() in the onPostExecute() and the activity ends almost immediately, leading me to believe the task is not even starting to play the audio file?

  • 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-27T17:46:12+00:00Added an answer on May 27, 2026 at 5:46 pm

    Make sure you are releasing the MediaPlayer class when a song is done playing otherwise you could see some strange behavior:

        mp.release();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been developing an app that supports streaming video and audio, among other
We're developing an android application that has several different tabs. We've been trying to
hi guys i have been developing android app that should match most of the
I have been developing android apps out of hobby and fun. I want to
I've been trying to experiment with developing Android applications with Scala. I've gotten to
I'm developing for Android and I have an app (called Forget-Me-Not) that uses a
I have been developing Android application since 3 to 4 months. I am naive,
I have been developing Android apps, but never did a live wallpaper. I have
I have been developing an Android app. I would like to hide the OK
In the app I'm developing for Android I'm letting users create files specific to

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.