Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- *
- */
- 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
- * <Code>TargetDataLine</Code> & 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 <Code>AudioInputStream</Code> from mentioned
- * <Code>TargetDataLine</Code>.
- *
- * @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 <Code>TargetDataLine</Code>.
- */
- public void start() {
- recLine.start();
- recorder = new Thread(this);
- recorder.start();
- }
- /**
- * It stops the recording process & stop the <Code>TargetDataLine</Code> and
- * then clear the current Thread.
- */
- public void stop() {
- recLine.stop();
- recLine.close();
- recorder = null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement