how to show the progress bar before playing the video

£可爱£侵袭症+ 提交于 2019-12-04 09:34:45

问题


i want to show the progress dialog before playing video. i tried below link example for playing video.

http://davanum.wordpress.com/2009/12/04/android-%E2%80%93-videomusic-player-sample-take-2/

it works but it takes more time to take for playing video so i want to show a progress dialog before start the video. so please tel me how to show the progress dialog before playing the video.

Thank you.

Best Regards.


回答1:


First, declare the progress dialog

private static ProgressDialog progressDialog;

Then, in onCreate, before calling runOnUiThread, start the dialog

progressDialog = ProgressDialog.show(this, "", "Loading...", true);

In playVideo, set a OnPreparedListener that will dismiss the dialog when the video is ready to play

mVideoView.setOnPreparedListener(new OnPreparedListener() {

    public void onPrepared(MediaPlayer arg0) {
        progressDialog.dismiss();
        mVideoView.start();
    }
});



回答2:


IMHO in this case it's more graceful to use ProgressBar widget insted of Progress dialog. It looks better on the video surface. You could add the progress bar to your activity's layout above the VideoView:

<ProgressBar 
    android:id="@+id/progress" 
    android:indeterminate="true" 
    android:indeterminateBehavior="repeat" 
    android:layout_width="100dp" 
    android:layout_height="100dp" 
    android:layout_gravity="center">
</ProgressBar>

In onCreate, before calling runOnUiThread, show the progress:

mProgress = (ProgressBar)findViewById(R.id.progress);
mProgress.setVisibility( View.VISIBLE );

In onPrepared callback hide the progress:

mProgress.setVisibility( View.INVISIBLE );



回答3:


I would suggest looking at the AsyncTask documentation, this seems ideally suited for doing video pre-loading. This will allow you to keep your UI thread stable during loading. There is an example of using the AsyncTask method here.

To add a progress dialog:

  • Create a private ProgressDialog object as part of an extension class of AsyncTask.
  • In the onPreExecute() method you can perform progress dialog setting up, such as: pd.setMessage(...) pd.setTitle(...) pd.show(...)
  • In the onPostExecute(...) method, dismiss the dialog: pd.dismiss();

Additionally, you can update the progress dialog using its incrementProgressBy(...) method, or alternately have a looping animation using the setIndeterminate(...) method. Giving the user feedback of the loaded progress is a good idea in UI design :)

I hope this helps!



来源:https://stackoverflow.com/questions/4921941/how-to-show-the-progress-bar-before-playing-the-video

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!