X-Git-Url: http://gitweb.fperrin.net/?a=blobdiff_plain;f=tim%2Fprune%2Fdata%2FAudioFile.java;fp=tim%2Fprune%2Fdata%2FAudioFile.java;h=43089ab85570526ad833bff0dcb68283165c167b;hb=f35b6d628f68e3b5ef19965ad8988d0dd1eb8efa;hp=0000000000000000000000000000000000000000;hpb=3745d70b1427bb8ac1a085e47cbdc566936784e1;p=GpsPrune.git diff --git a/tim/prune/data/AudioFile.java b/tim/prune/data/AudioFile.java new file mode 100644 index 0000000..43089ab --- /dev/null +++ b/tim/prune/data/AudioFile.java @@ -0,0 +1,45 @@ +package tim.prune.data; + +import java.io.File; +import javax.sound.sampled.AudioFileFormat; +import javax.sound.sampled.AudioSystem; + +/** + * Class to represent an audio file for correlation + */ +public class AudioFile extends MediaFile +{ + /** length of current audio file in seconds */ + private int _lengthInSeconds = LENGTH_UNKNOWN; + + private static final int LENGTH_UNKNOWN = -1; + private static final int LENGTH_NOT_AVAILABLE = -2; + + /** + * Constructor + * @param inFile file object + */ + public AudioFile(File inFile) + { + // Timestamp is always just taken from the file modification stamp + super(inFile, new Timestamp(inFile.lastModified())); + } + + /** + * @return length of this audio file in seconds + */ + public int getLengthInSeconds() + { + if (_lengthInSeconds == LENGTH_UNKNOWN) + { + try { + AudioFileFormat format = AudioSystem.getAudioFileFormat(getFile()); + _lengthInSeconds = (int) (format.getFrameLength() / format.getFormat().getFrameRate()); + } + catch (Exception e) { + _lengthInSeconds = LENGTH_NOT_AVAILABLE; + } + } + return _lengthInSeconds; + } +}