如何在播放视频前显示进度条
我想在播放视频之前显示进度对话框。我尝试了下面的链接示例来播放视频。
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
首先,声明进度对话框
然后,在 onCreate 中,在调用 runOnUiThread 之前,启动对话框
在 playVideo 中,设置一个 OnPreparedListener,当视频准备好播放时,它将关闭对话框
First, declare the progress dialog
Then, in onCreate, before calling runOnUiThread, start the dialog
In playVideo, set a OnPreparedListener that will dismiss the dialog when the video is ready to play
恕我直言,在这种情况下,使用 ProgressBar 小部件而不是“进度”对话框会更优雅。在视频表面看起来更好。您可以将进度条添加到 VideoView 上方的 Activity 布局中:
在 onCreate 中,调用 runOnUiThread 之前,显示进度:
在 onPrepared 回调中隐藏进度:
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:
In onCreate, before calling runOnUiThread, show the progress:
In onPrepared callback hide the progress:
我建议查看 AsyncTask 文档,这似乎非常适合做视频预加载。这将使您在加载期间保持 UI 线程稳定。有一个使用 AsyncTask 方法的示例 在这里。
要添加进度对话框:
对象作为扩展类的一部分
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:
object as part of an extension class
of AsyncTask.
onPreExecute()
method you can perform progress dialog settingup, such as:
pd.setMessage(...) pd.setTitle(...) pd.show(...)
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 thesetIndeterminate(...)
method. Giving the user feedback of the loaded progress is a good idea in UI design :)I hope this helps!