videoView 与 seekBar,seekTo 与 seekBar 进度
videoView with seekBar, seekTo with seekBar progress
现在搜索栏按照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) {
}
}
如果你知道如何解决这个问题,请告诉我。感谢您阅读此问题!
在这个方法中
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
}
现在搜索栏按照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) {
}
}
如果你知道如何解决这个问题,请告诉我。感谢您阅读此问题!
在这个方法中
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
}