现在,搜索栏根据videoView的流向移动。但是,我在开发搜索条方面很难。
这是我的密码。
public class PreviewingActivity extends AppCompatActivity implements SeekBar.OnSeekBarChangeListener {
private static final String TAG = "PreviewingActivity";
private ImageView playBtn, pauseBtn;
private VideoView recVideo;
private String videoPath;
private SeekBar seekBar;
private boolean isSeekbarTouch = false;
private Handler updateHandler = new Handler();
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_previewing);
playBtn = (ImageView) findViewById(R.id.play_btn);
pauseBtn = (ImageView) findViewById(R.id.pause_btn);
recVideo = (VideoView) findViewById(R.id.rec_video);
seekBar = (SeekBar) findViewById(R.id.seek_bar);
Intent intent = getIntent();
videoPath = intent.getStringExtra("recVideoPath");
recVideo.setVideoPath(videoPath);
playBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
recVideo.start();
playBtn.setVisibility(View.GONE);
pauseBtn.setVisibility(View.VISIBLE);
}
});
pauseBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
recVideo.pause();
playBtn.setVisibility(View.VISIBLE);
pauseBtn.setVisibility(View.GONE);
}
});
recVideo.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
playBtn.setVisibility(View.VISIBLE);
pauseBtn.setVisibility(View.GONE);
}
});
recVideo.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mediaPlayer) {
seekBar.setProgress(0);
seekBar.setMax(recVideo.getDuration());
updateHandler.postDelayed(updateVideoTime, 100);
}
});
}
private Runnable updateVideoTime = new Runnable() {
@Override
public void run() {
long currentPosition = recVideo.getCurrentPosition();
seekBar.setProgress((int) currentPosition);
updateHandler.postDelayed(this, 100);
}
};
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean b) {
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
}
如果您知道如何解决此问题,请告诉我。感谢您阅读此问题!
答案 0 :(得分:1)
采用这种方法
SeekBar seekBar, int progress, boolean b
if(b) {
// Mean that the seekbar value is changed by user
videoView.seekTo((progress*duration)/100); // Verify this
} else {
// Ignore becuase is due to seekBar programmatically change
}