在视频持续时间之后,如何更改progressBar的位置?

时间:2013-02-08 09:46:40

标签: android video progress-bar android-videoview seek

我有以下代码:

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;
            }
        }
    });

现在,如果我移动progressBar(videoBar),它会将视频带到视频的那一部分,但如果视频播放,则不会移动到进度条。如何制作,在视频播放时移动进度条?

1 个答案:

答案 0 :(得分:0)

这帮助我做对了,现在它有效。第一个答案

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