Get the progress time of the video played under videoview?

后端 未结 4 558
温柔的废话
温柔的废话 2020-11-28 07:51

I need to get the progress time of the video that is played in \"VideoView\"(ie the time shown in the left hand side in progress bar).

Any help will really be apprec

4条回答
  •  情歌与酒
    2020-11-28 08:12

    You can use Thread for this purpose like below:

    videoView.start();
        videoView.setOnPreparedListener(new OnPreparedListener() {
            public void onPrepared(MediaPlayer mp) {
                running = true;
                final int duration = videoView.getDuration();
    
                new Thread(new Runnable() {
                    public void run() {  
                        do{                         
                            textView.post(new Runnable() {
                             public void run() {
                                int time = (duration - videoView.getCurrentPosition())/1000;
                                textView.setText(time+"");
                             }
                            });
                            try {
                                Thread.sleep(500);
                            } catch (InterruptedException e) {                                      
                                e.printStackTrace();
                            }
                            if(!running) break;
                        }
                        while(videoView.getCurrentPosition()

提交回复
热议问题