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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:41:05+00:00 2026-05-23T08:41:05+00:00

I am trying to figure out how to have a progress bar that says

  • 0

I am trying to figure out how to have a progress bar that says “Loading. Please Wait…” while my media player prepares a streaming file. What occurs now is that it displays after the song is prepared. how can i fix this?

        mediaPlayerLoadingBar =ProgressDialog.show(PlaylistActivity.this, "", "Loading. Please wait...", true);         
                    /*dubstep stream*/
                    try {
                        dubstepMediaPlayer.setDataSource(dubstepPlaylistString[0]);
                        dubstepMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
                        dubstepMediaPlayer.prepare();

                    } catch (IllegalArgumentException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (SecurityException 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();
                    }


                    dubstepMediaPlayer.start();
                    if(dubstepMediaPlayer.isPlaying()){
                        mediaPlayerLoadingBar.dismiss();
                    }`

EDIT:
This is the code I have now:

`switch(pSelection){
case 1:

                    new AsyncTask<Void, Void, Void>(){

                    @Override
                    protected void onPreExecute(){
                        mediaPlayerLoadingBar =ProgressDialog.show(PlaylistActivity.this, "", "Loading. Please wait...", true);
                        try {
                            dubstepMediaPlayer.setDataSource(dubstepPlaylistString[0]);
                        } 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();
                        }
                        dubstepMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
                    }

                    @Override
                    protected Void doInBackground(Void... params) {
                        // TODO Auto-generated method stub
                        //mediaPlayerLoadingBar =ProgressDialog.show(PlaylistActivity.this, "", "Loading. Please wait...", true);
                        return null;
                    }

                    protected void onPostExecute(Void result){
                        //mediaPlayerLoadingBar =ProgressDialog.show(PlaylistActivity.this, "", "Loading. Please wait...", true)
                            dubstepMediaPlayer.prepareAsync();
                        dubstepMediaPlayer.start();
                        mediaPlayerLoadingBar.dismiss();

                }

                }.execute();`
  • 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-23T08:41:05+00:00Added an answer on May 23, 2026 at 8:41 am

    The issue lies in that you are not doing anything asynchronously here, and you should be. You should use an AsyncTask to do your work.

    Take a look at ‘the 4 steps’, as detailed here:

    The 4 steps

    When an asynchronous task is executed, the task goes through 4 steps:

    1. onPreExecute(), invoked on the UI thread immediately after the task is executed. This step is normally used to setup the task, for
      instance by showing a progress bar in the user interface.
    2. doInBackground(Params…), invoked on the background thread immediately after onPreExecute() finishes executing. This step is used
      to perform background computation that can take a long time. The
      parameters of the asynchronous task are passed to this step. The
      result of the computation must be returned by this step and will be
      passed back to the last step. This step can also use
      publishProgress(Progress…) to publish one or more units of progress.
      These values are published on the UI thread, in the
      onProgressUpdate(Progress…) step.
    3. onProgressUpdate(Progress…), invoked on the UI thread after a call to publishProgress(Progress…). The timing of the execution is
      undefined. This method is used to display any form of progress in the
      user interface while the background computation is still executing.
      For instance, it can be used to animate a progress bar or show logs in
      a text field.
    4. onPostExecute(Result), invoked on the UI thread after the background computation finishes. The result of the background
      computation is passed to this step as a parameter.

    EDIT:

    You can create an anonymous inner class to do your bidding, which may be similar to how you are creating your onClick handler. In your onClick do something like this:

    //pseudo-code...
    onClick(View v, ...) {
        new AsyncTask<Generic1, Generic2, Generic3>() {
            protected void onPreExecute() {
                // do pre execute stuff...
            }
    
            protected Generic3 doInBackground(Generic1... params) {
                // do background stuff...
            }
    
            protected void onPostExecute(Generic3 result) {
                // do post execute stuff...
            }
        }.execute();
    }
    

    Don’t forget to keep an eye on your generics here!

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

Sidebar

Related Questions

I'm trying to figure out a way to run a progress loader while google
I am trying to figure out how to have a scrollable div that only
Trying to figure out how to have a .procmailrc rule that tosses all mail
I am trying to figure out how to have a fluid template that can
I'm trying to figure out how to incorporate a progress bar within the status
I'm trying to figure out how to have a short, one line conditional statement.
trying to figure out why this is happening - I have an input text
I have been trying to figure out why I am getting this problem and
I have been trying to figure out how to read paragraph content which exists
I have been trying to figure out how to open a file from 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.