How can i change the position of a progressBar, after the duration of a videoView?

对着背影说爱祢 提交于 2020-01-06 09:55:06

问题


i have the following code:

final SeekBar videoBar = (SeekBar) findViewById(R.id.videoBar);
final VideoView videoView = (VideoView) findViewById(R.id.videoViewPaint);
videoView.setVideoPath(videoPath);
videoView.start();
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                        @Override
                        public void onPrepared(MediaPlayer mp) {
                            long duration = videoView.getDuration();
                            videoBar.setMax((int) duration);
                            LogService.log("in runnable", "videoView duration= " + videoView.getDuration());
                        }
                    });
videoBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            if (isVideo) {
                videoView.seekTo(progress);
            }
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }
    });
playBtn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            if (isPlaying) {
                // Button is ON
                videoView.pause();
                playBtn.setImageResource(R.drawable.play);// Do Something
                isPlaying = false;
            } else if (!isPlaying) {
                // Button is OFF
                videoView.start(); // Do Something
                playBtn.setImageResource(R.drawable.pause);
                isPlaying = true;
            }
        }
    });

Now if i move the progressBar (videoBar), it takes the the video to that part of the video, but if the video plays, it does not move to progress bar, alongside. How can I make it, move the progress bar while the video is playing?


回答1:


This helped me get it right, now it works. The first answer

How to use a Seekbar in android as a seekBar as well as a progressBar simultaneously?



来源:https://stackoverflow.com/questions/14769723/how-can-i-change-the-position-of-a-progressbar-after-the-duration-of-a-videovie

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