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

    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..
    plssss..
    Java Code:
    import javax.sound.sampled.AudioSystem;
    import javax.sound.sampled.Clip;
    import javax.sound.sampled.DataLine;
    import java.lang.*;
    import java.io.*;
    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 =
                 AudioSystem.getAudioInputStream(f1);
                System.out.println("File AudioFormat: " + fis.getFormat());
                AudioInputStream ais = AudioSystem.getAudioInputStream(
                 AudioFormat.Encoding.PCM_SIGNED,fis);
                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 05:33 AM.

Similar Threads

  1. duration of the audio file
    By Saran185 in forum Java Applets
    Replies: 2
    Last Post: 02-14-2011, 05:31 AM
  2. Play Audio File
    By YapperNico in forum New To Java
    Replies: 0
    Last Post: 12-30-2010, 01:59 PM
  3. Get Duration of mov ,wmv files
    By saurabh208 in forum New To Java
    Replies: 7
    Last Post: 06-18-2010, 03: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, 03: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, 12: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
  •