Android在VideoView启动之前加载动画

发布于 2024-11-04 22:12:24 字数 95 浏览 2 评论 0原文

我没有找到任何解决方案来在 VideoView 开始播放之前显示加载动画(或仅显示 imageView):在视频缓冲期间。

有人知道吗?

谢谢。

I don't find any solution to show a loading animation (or just an imageView) before a VideoView start to play : during the video is buffering.

Does anyone have a clue ?

Thanks.

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

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

发布评论

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

评论(3

风透绣罗衣 2024-11-11 22:12:24

或者您可以只使用进度对话框;

public class VideoEkrani extends Activity {

    VideoView ekran;
    String kaynakYolu = "http://commonsware.com/misc/test2.3gp";
    ProgressDialog progDailog;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sayfa_video_goruntule);


        ekran = (VideoView) findViewById(R.id.videoViewESPU);
        ekran.setMediaController(new MediaController(this));
        ekran.setVideoURI(Uri.parse(kaynakYolu));
        ekran.requestFocus();
        ekran.start();

        progDailog = ProgressDialog.show(this, "Please wait ...", "Retrieving data ...", true);

        ekran.setOnPreparedListener(new OnPreparedListener() {

            public void onPrepared(MediaPlayer mp) {
                // TODO Auto-generated method stub
                progDailog.dismiss();
            }
        });
    }
}

Or you can just use Progress Dialog;

public class VideoEkrani extends Activity {

    VideoView ekran;
    String kaynakYolu = "http://commonsware.com/misc/test2.3gp";
    ProgressDialog progDailog;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sayfa_video_goruntule);


        ekran = (VideoView) findViewById(R.id.videoViewESPU);
        ekran.setMediaController(new MediaController(this));
        ekran.setVideoURI(Uri.parse(kaynakYolu));
        ekran.requestFocus();
        ekran.start();

        progDailog = ProgressDialog.show(this, "Please wait ...", "Retrieving data ...", true);

        ekran.setOnPreparedListener(new OnPreparedListener() {

            public void onPrepared(MediaPlayer mp) {
                // TODO Auto-generated method stub
                progDailog.dismiss();
            }
        });
    }
}
呆萌少年 2024-11-11 22:12:24

最后我找到了VideoView上的方法setOnPreparedListener()

我在布局中添加了一个 ProgressBar,并使用 OnPreparedListener 隐藏它

Finally I found the method setOnPreparedListener() on VideoView.

I added a ProgressBar inside my layout, and hide it with the OnPreparedListener

江南烟雨〆相思醉 2024-11-11 22:12:24

您无法在 MediaPlayer 上使用 OnBufferingUpdateListener 检测视频缓冲区。如果您使用 VideView,请在 OnPreparedListener 内设置该侦听器。

videoview.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
   public void onPrepared(MediaPlayer mp) {
     mp.setOnBufferingUpdateListener(new MediaPlayer.OnBufferingUpdateListener() {
       @Override
       public void onBufferingUpdate(MediaPlayer mp, int percent) {
         if(percent == 100){
           //video have completed buffering
         }
       }
     });
   }
});

You cant detect the video buffer using OnBufferingUpdateListener on MediaPlayer. If you use VideView set that listener inside OnPreparedListener.

videoview.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
   public void onPrepared(MediaPlayer mp) {
     mp.setOnBufferingUpdateListener(new MediaPlayer.OnBufferingUpdateListener() {
       @Override
       public void onBufferingUpdate(MediaPlayer mp, int percent) {
         if(percent == 100){
           //video have completed buffering
         }
       }
     });
   }
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文