2011-12-16 86 views
1

我在我的应用程序中使用了seekbar来显示音轨位置。当活动是 第一次启动时,它工作正常。它处理触摸事件,根据触摸事件转发或转发音频,并显示搜索栏阴影部分。这意味着它工作正常......Seekbar无法处理触摸事件

但是,当活动进入背景并再次返回前台时,我尝试手动移动搜索栏,根据触摸事件转发歌曲位置,但是搜索栏阴影区域不会被来自用户的触摸事件更新...

为什么它是这样的?

@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

尝试重写seek Bar类,在覆盖方法中设置视频/音频的位置并将正确的逻辑实现为OnResume方法。 – Yahor10 2011-12-16 13:16:41

回答

0

这可能是由于没有实现SeekBar对象的SaveState。就像没有onConfigurationChanged(newConfig)实现一样。