Results 1 to 1 of 1
  1. #1
    Saran185 is offline Member
    Join Date
    Jan 2011
    Rep Power

    Question duration of audio file

    hi . i have my code below to get the duration of audio file.
    but i get an exception error. can anyone fix the bug and help me in getting the duration of the audio file..
    Java Code:
    import javax.sound.sampled.AudioSystem;
    import javax.sound.sampled.Clip;
    import javax.sound.sampled.DataLine;
    import java.lang.*;
    import javax.sound.sampled.*;
    public class Main {
      public static void main(String[] argv) throws Exception {
        File f1 = new File("c:/program files/java/jdk1.6.0/bin/demo.mp3");
                AudioInputStream fis =
                System.out.println("File AudioFormat: " + fis.getFormat());
                AudioInputStream ais = AudioSystem.getAudioInputStream(
                AudioFormat af = ais.getFormat();
    			// int frmlength = (int)ais.getByteLength();
                System.out.println("AudioFormat: " + af.toString());
                 DataLine.Info info = new DataLine.Info(SourceDataLine.class,af);
        Clip clip = (Clip) AudioSystem.getLine(info);
        double durationInSecs = clip.getBufferSize()
            / (clip.getFormat().getFrameSize() * clip.getFormat().getFrameRate());
    		System.out.println("duration new : "+durationInSecs);
    Last edited by Saran185; 02-25-2011 at 06:33 AM.

Similar Threads

  1. duration of the audio file
    By Saran185 in forum Java Applets
    Replies: 2
    Last Post: 02-14-2011, 06:31 AM
  2. Play Audio File
    By YapperNico in forum New To Java
    Replies: 0
    Last Post: 12-30-2010, 02:59 PM
  3. Get Duration of mov ,wmv files
    By saurabh208 in forum New To Java
    Replies: 7
    Last Post: 06-18-2010, 04:42 PM
  4. Is it possible to insert recorded audio data into an existing file?
    By evan_earnest in forum Threads and Synchronization
    Replies: 1
    Last Post: 01-31-2010, 04:40 AM
  5. How to calculate the sample rate of an audio file?
    By arnab321 in forum CLDC and MIDP
    Replies: 0
    Last Post: 12-28-2008, 01:39 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts