我正在使用Android构建使用VideoView的视频播放器。 我已经设法让视频播放器运行,现在我使用天文台设置了一个计数器,当我选择该文件时,该计时器开始打勾。
但是,当剪辑开始时,视频剪辑需要几秒钟才能开始运行,而定时器已经开始计算几秒钟。带定时器的Android Sync视频
如何编码以将计数器与媒体文件同步?
我检查过,但似乎无法找到答案。
video = (VideoView) findViewById(R.id.video);
play = (Button) findViewById(R.id.play);
pause = (Button) findViewById(R.id.pause);
stop = (Button) findViewById(R.id.stop);
reset = (Button) findViewById(R.id.reset);
Chronometer counter = (Chronometer) findViewById(R.id.chrono);
startTime = SystemClock.elapsedRealtime();
time = (TextView) findViewById(R.id.time);
try {
video.setVideoPath(link);
video.start();
video.requestFocus();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
}
play.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
video.start();
video.requestFocus();
}
});
pause.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
video.pause();
}
});
stop.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
try {
video.stopPlayback();
video.setVideoPath(link);
} catch (IllegalStateException e) {
e.printStackTrace();
}
}
});
reset.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
try {
video.seekTo(0);
video.start();
video.requestFocus();
} catch (IllegalStateException e) {
e.printStackTrace();
}
}
});
counter.setOnChronometerTickListener(new OnChronometerTickListener(){
public void onChronometerTick(Chronometer arg0) {
countUp = (SystemClock.elapsedRealtime() - arg0.getBase())/1000;
duration = video.getDuration();
if (countUp % 60 <= 9) {
countText = (countUp/60) + ":0" + (countUp % 60);
} else {
countText = (countUp/60) + ":" + (countUp % 60);
}
if (duration % 60000 <= 9) {
durationText = (duration/60000) + ":0" + (duration % 60000);
} else {
durationText = (duration/60000) + ":" + (duration % 60000);
}
time.setText(countText + "/" + durationText);
}
});
counter.start();