2011-12-16 105 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)實現一樣。