/**
*
*/
package com.actura.app.capture;
import java.io.File;
import java.io.IOException;
import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.TargetDataLine;
/**
* It performs all the recording tasks behind the scene.
*
* @author Mihir Parekh
*
* @version 1.0
*/
public class ActuraRecorder implements Runnable {
/**
* which is the line from hardware analog mixer from which we capture
* sounds.
*/
private TargetDataLine recLine = null;
/**
* the file in which we stores our recording at client side.
*/
private File outputFile = null;
/**
* the recording audio File format Type By default it is WAV
*/
private AudioFileFormat.Type targetType = null;
/**
* which is AudioInputStream which takes bits from
* TargetDataLine
& automatically converts the bytes into
* specified format.
*/
private AudioInputStream myAIS = null;
/**
* performs the actual task of recording.
*/
private Thread recorder = null;
/**
* Default Constructor
*/
private ActuraRecorder() {
}
/**
* Explicit Constructor for this class to be called by its clients to
* instantiate and fulfill the purpose of the recording. It also instantiate
* the desired AudioInputStream
from mentioned
* TargetDataLine
.
*
* @param recordLine
* on which we perform recording.
* @param targetType
* the target audio file type.
* @param outputFile
* the audio file in which we store recorded sound.
*/
public ActuraRecorder(TargetDataLine recordLine,
AudioFileFormat.Type targetType, File outputFile) {
this();
this.recLine = recordLine;
myAIS = new AudioInputStream(this.recLine);
this.outputFile = outputFile;
this.targetType = targetType;
}
@Override
public void run() {
try {
AudioSystem.write(myAIS, targetType, outputFile);
} catch (IOException e) {
// TODO provide runtime exception to reach it to presentation
// layer
e.printStackTrace();
}
}
/**
* by calling this methods actual recording starts in specified file from
* specified TargetDataLine
.
*/
public void start() {
recLine.start();
recorder = new Thread(this);
recorder.start();
}
/**
* It stops the recording process & stop the TargetDataLine
and
* then clear the current Thread.
*/
public void stop() {
recLine.stop();
recLine.close();
recorder = null;
}
}