daily pastebin goal
83%
SHARE
TWEET

Untitled

a guest Sep 14th, 2018 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. mCurrentPosition = mediaPlayer.getCurrentPosition()/1000; // In milliseconds
  2.    
  3. protected void initializeSeekBar(){
  4.     mSeekBar.setMax(mediaPlayer.getDuration()/1000);
  5.  
  6.     mRunnable = new Runnable() {
  7.         @Override
  8.         public void run() {
  9.             int mCurrentPosition;
  10.             if(mediaPlayer!=null && mediaPlayer.isPlaying()){
  11.                 mCurrentPosition = mediaPlayer.getCurrentPosition()/1000; // In milliseconds
  12.             }
  13.             else    {
  14.                 mCurrentPosition = 0;
  15.             }
  16.  
  17.             if (mSeekBar != null)   {
  18.                 mSeekBar.setProgress(mCurrentPosition);
  19.                 getAudioStats();
  20.             }
  21.             handler.postDelayed(mRunnable,1000);
  22.         }
  23.     };
  24.     handler.postDelayed(mRunnable,1000);
  25. }
  26.    
  27. mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
  28.             @Override
  29.             public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
  30.                 getAudioStats();
  31.                 initializeSeekBar();
  32.  
  33.                 if(mediaPlayer != null && fromUser) {
  34.                     mediaPlayer.seekTo(progress * 1000);
  35.                 }
  36.  
  37.  
  38.             }
  39.  
  40.             @Override
  41.             public void onStartTrackingTouch(SeekBar seekBar) {
  42.  
  43.             }
  44.  
  45.             @Override
  46.             public void onStopTrackingTouch(SeekBar seekBar) {
  47.  
  48.             }
  49.         });
  50.  
  51. protected void getAudioStats(){
  52.         long duration  = mediaPlayer.getDuration()/1000; // In milliseconds
  53.         long due = (mediaPlayer.getDuration() - mediaPlayer.getCurrentPosition())/1000;
  54.         long pass = duration - due;
  55.  
  56.         String test = DateUtils.formatElapsedTime(pass);
  57.         String test1 = DateUtils.formatElapsedTime(due);
  58.  
  59.         current_time.setText("" + test);
  60.         //mDuration.setText("" + duration + " seconds");
  61.         total_time.setText("" + test1);
  62.     }
  63.    
  64. handler.removeCallbacks(mRunnable);
  65.    
  66. handler.postDelayed(mRunnable,1000);
  67.    
  68. if (!isDestroyed()) {
  69.     handler.postDelayed(mRunnable,1000);
  70. }
  71.    
  72. protected void initializeSeekBar(){
  73.     if (mRunnable != null) {
  74.         handler.removeCallbacks(mRunnable);
  75.     }
  76.     // ... the rest of the method that you currently have
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top