title: get duration of audio file
body: <p>I have made a voice recorder app, and I want to show the duration of the recordings in a listview. I save the recordings like this:</p>
  
  <pre><code>MediaRecorder recorder = new MediaRecorder();
  recorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
  recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
  folder = new File(Environment.getExternalStorageDirectory()
              + File.separator + "Audio recordings");
  String[] files = folder.list();
      int number = files.length + 1;
      String filename = "AudioSample" + number + ".mp3";
      File output = new File(Environment.getExternalStorageDirectory()
              + File.separator + "Audio recordings" + File.separator
              + filename);
      FileOutputStream writer = new FileOutputStream(output);
      FileDescriptor fd = writer.getFD();
      recorder.setOutputFile(fd);
      try {
          recorder.prepare();
          recorder.start();
      } catch (IllegalStateException e) {
          e.printStackTrace();
      } catch (IOException e) {
          Log.e(LOG_TAG, "prepare() failed");
          e.printStackTrace();
      }
  </code></pre>
  
  <p>How can I get the duration in seconds of this file?</p>
  
  <p>Thanks in advance</p>
  
  <p>---EDIT
  I got it working, I called MediaPlayer.getduration() inside the MediaPlayer.setOnPreparedListener() method so it returned 0.</p>