我在我的应用程序中使用了搜索栏来显示音轨位置。当活动是 第一次开始,它工作正常。它处理触摸事件,根据触摸事件转发或反向音频,并且也显示搜索条阴影部分。这意味着它工作正常......
但是当活动进入后台并再次返回到前景并且我尝试手动移动搜索栏时,根据触摸事件转发和反转歌曲位置但是搜索栏阴影区域不会被来自的触摸事件更新用户......
为什么会这样?
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.audioplayer);
layout = (LinearLayout) findViewById(R.id.audioplayerlayout);
layoutui1 = (LinearLayout) findViewById(R.id.audiolayoutui1);
layoutui2 = (LinearLayout) findViewById(R.id.audiolayoutui2);
c = Calendar.getInstance();
c.setTimeInMillis(System.currentTimeMillis());
hour = c.get(Calendar.HOUR_OF_DAY);
minute = c.get(Calendar.MINUTE);
audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
int maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
int curVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
volControl = (SeekBar) findViewById(R.id.seekbarVolume);
volControl.setMax(maxVolume);
muteButton = (ImageButton) findViewById(R.id.mutebutton);
muteButton.setOnClickListener(this);
muteButton.setBackgroundColor(color.transparent);
setwakeupButton = (Button) findViewById(R.id.WakeupAlarmButtom);
setwakeupButton.setOnClickListener(new OnClickListener() {
volControl.setProgress(curVolume);
play = (ImageButton) findViewById(R.id.btnplay);
// view = (TextView)findViewById(R.id.progressview);
bar = (SeekBar) findViewById(R.id.seekbartrack);
textview = (TextView) findViewById(R.id.textView1);
textview.setText("");
// listeners...
play.setOnClickListener(this);
play.setBackgroundColor(color.transparent);
application = (videoplayerapplication) getApplication();
application.play();
volControl.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
public void onStopTrackingTouch(SeekBar seekBar) {
}
public void onProgressChanged(SeekBar seekBar, int progressvol,
boolean fromUser) {
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC,
progressvol, 50);
}
public void onStartTrackingTouch(SeekBar seekBar) {
}
});
{
duration = (application.getDuration() / 1000);
d = (int) (duration);
Log.v("duraton .....", "" + d);
bar.setMax(d);
countdown(d);
Log.v("The value of keeptrack", "" + toKeepTrackValue);
}
bar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
public void onStopTrackingTouch(SeekBar seekBar) {
}
public void onStartTrackingTouch(SeekBar seekBar) {
}
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// check whether the user has touched the bar
if (fromUser) {
application.seekforward(progress);
i = progress;
prog = progress;
count.cancel();
countdown((application.getDuration() / 1000) - progress);
}
}
});
}
public void countdown(double convert) {
count = new CountDownTimer((long) (convert * 1000), 1000) {
@Override
public void onTick(long millisecond) {
conversion = millisecond;
StringBuilder b = new StringBuilder();
b.append("" + conversion / 60000);
newposition=(int) (conversion / 60000);
textview.setText(b.substring(0, 4));
bar.setProgress((int) (conversion / 60000));
if (toKeepTrackValue == false) {
bar.setProgress(i++);
}
if (toKeepTrackValue == true) {
Log.v("the getseekpos", "" + getSeekPosition);
bar.setProgress(getSeekPosition++);
}
}
@Override
public void onFinish() {
// finish......
bar.setProgress(0);
i = 0;
textview.setText(" 0.0");
play.setImageResource(R.drawable.play);
checkAudioTrackFinish = 2;
textview.setText(" 26:46");
}
}.start();
}
答案 0 :(得分:0)
可能是由于没有实现SeekBar对象的SaveState。就像没有onConfigurationChanged(newConfig)实现一样。