2009-12-03 67 views

回答

6

嗨,你可以使用下面的代碼來定製搜索條implemen爲您的視頻來看,

videoView.setOnPreparedListener(new OnPreparedListener() { 

      @Override 
      public void onPrepared(MediaPlayer mp) { 

       seekBar.setMax(videoView.getDuration()); 
       seekBar.postDelayed(onEverySecond, 1000); 
      } 
     }); 

    private Runnable onEverySecond=new Runnable() { 

     @Override 
     public void run() { 

      if(seekBar != null) { 
       seekBar.setProgress(videoView.getCurrentPosition()); 
      } 

      if(videoView.isPlaying()) { 
       seekBar.postDelayed(onEverySecond, 1000); 
      } 

     } 
    }; 

seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { 

     @Override 
     public void onStopTrackingTouch(SeekBar seekBar) { 
     } 

     @Override 
     public void onStartTrackingTouch(SeekBar seekBar) { 
     } 

     @Override 
     public void onProgressChanged(SeekBar seekBar, int progress, 
       boolean fromUser) { 

      if(fromUser) { 
       // this is when actually seekbar has been seeked to a new position 
       videoView.seekTo(progress); 
      } 
     } 
    }); 
+0

感謝兄弟。你太好了 – 2015-12-21 07:07:14