如何在播放视频前显示进度条

发布于 2024-10-16 03:28:35 字数 359 浏览 2 评论 0原文

我想在播放视频之前显示进度对话框。我尝试了下面的链接示例来播放视频。

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

它可以工作,但播放视频需要更多时间,所以我想要在开始视频之前显示进度对话框。所以请告诉我如何在播放视频之前显示进度对话框。

谢谢。

此致。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

深海里的那抹蓝 2024-10-23 03:28:35

首先,声明进度对话框

private static ProgressDialog progressDialog;

然后,在 onCreate 中,在调用 runOnUiThread 之前,启动对话框

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

在 playVideo 中,设置一个 OnPreparedListener,当视频准备好播放时,它将关闭对话框

mVideoView.setOnPreparedListener(new OnPreparedListener() {

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

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();
    }
});
浅唱ヾ落雨殇 2024-10-23 03:28:35

恕我直言,在这种情况下,使用 ProgressBar 小部件而不是“进度”对话框会更优雅。在视频表面看起来更好。您可以将进度条添加到 VideoView 上方的 Activity 布局中:

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

在 onCreate 中,调用 runOnUiThread 之前,显示进度:

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

在 onPrepared 回调中隐藏进度:

mProgress.setVisibility( View.INVISIBLE );

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 );
故事与诗 2024-10-23 03:28:35

我建议查看 AsyncTask 文档,这似乎非常适合做视频预加载。这将使您在加载期间保持 UI 线程稳定。有一个使用 AsyncTask 方法的示例 在这里

要添加进度对话框:

  • 创建一个私有 ProgressDialog
    对象作为扩展类的一部分
    AsyncTask 的。
  • onPreExecute()方法中可以进行进度对话框设置
    上,如:
    pd.setMessage(...) pd.setTitle(...) pd.show(...)
  • onPostExecute(...) 方法中,关闭对话框:pd.dismiss();

此外,您可以使用其 incrementProgressBy(...) 方法更新进度对话框,或者使用 incrementProgressBy(...) 方法创建循环动画>setInstituteate(...) 方法。在 UI 设计中,向用户提供加载进度的反馈是一个好主意:)

我希望这会有所帮助!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文