title: How to use Slider for MP3 Audio File Duration in Java?
body: <p>I want to make an program in Java to play MP3 files. I use JLayer jar to play MP3 Files and mp3agic jar to display mp3 file tags like artist name etc.
  One thing I want to ask you all is that how can I use JSlider in my code to 
  seek to a duration(time) of my MP3 File using Slider?Also please let me know if I have to use external JARs</p>
  
  <p>Here is the code:</p>
  
  <pre><code>import javazoom.jl.decoder.JavaLayerException;
  import com.mpatric.mp3agic.InvalidDataException;
  import com.mpatric.mp3agic.Mp3File;
  import com.mpatric.mp3agic.UnsupportedTagException;
  import javazoom.jl.player.advanced.*;
  import java.awt.FileDialog;
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.FileNotFoundException;
  import java.io.IOException;
  import javax.swing.*;
  import javax.swing.event.ChangeEvent;
  import javax.swing.event.ChangeListener;
  public class MP3Player extends JFrame implements ChangeListener{
  JFrame f;
  JSlider sl;
  FileInputStream fis;
  AdvancedPlayer pl;
  Mp3File mp3tags;
  String s;
  MP3Player() throws JavaLayerException,IOException, UnsupportedTagException, InvalidDataException
  {
      f=new JFrame();
      f.setTitle("MP3 Player");
      f.setBounds(250, 150, 500, 500);
  FileDialog fd=new FileDialog(f,"Select Audio File",FileDialog.LOAD);
  fd.setVisible(true);
  FileInputStream fis=new FileInputStream(new File(fd.getDirectory(),fd.getFile()));
  pl=new AdvancedPlayer(fis);
  s=fd.getDirectory()+fd.getFile();
  mp3tags=new Mp3File(s);
  System.out.println(mp3tags.getId3v2Tag().getArtist());
  new Thread()
  {
      public void run()
      {
          try {
              pl.play();
          } catch (JavaLayerException e) {
              e.printStackTrace();
          }
      }
  }.start();
  sl=new JSlider();
  sl.setBounds(250, 500, 500, 500);
  f.add(sl);
  sl.setMinimum(0);
  sl.setValue(0);
  sl.addChangeListener(this);
  }
  public static void main(String asrar[]) throws JavaLayerException,IOException, UnsupportedTagException, InvalidDataException
  {
      MP3Player mp3=new MP3Player();
      mp3.f.setVisible(true);
  }
  @Override
  public void stateChanged(ChangeEvent e) {
  
  }
  }
  </code></pre>