Results 1 to 1 of 1
Thread: Audiosystem.write not returning?
- 01-31-2012, 01:06 PM #1
Member
- Join Date
- Jul 2011
- Posts
- 22
- Rep Power
- 0
Audiosystem.write not returning?
Hello,
I am doing a task which involves screenshot and sound capture, but I am having problems with AudioSystem.write, in run(). The method doesn't seem to return whether I have a mic plugged in or not, and a blank .wav file seems to be written. Can someone help?
Here is my output:
1. Entered main function
2. Entered Capture class
Writing file: 2012-01-31_11-56-47.jpg
Write Successful: 2012-01-31_11-56-47.jpg
3. Entered main_soundcapture
4. Audio/file formats initialised
5. TargetDataline grabbed
Press ENTER to start the recording.
Started recording
Try audiosystem.write
Please ignore the block comments, I don't know what happened there.
Java Code:import java.io.File; import java.io.IOException; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import javax.sound.sampled.AudioFileFormat; import javax.sound.sampled.AudioFormat; import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.DataLine; import javax.sound.sampled.LineUnavailableException; import javax.sound.sampled.TargetDataLine; public class SoundCapture { TargetDataLine m_line; AudioFileFormat.Type m_targetType; AudioInputStream m_audioInputStream; File m_outputFile; DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss"); public void main_soundcapture() { System.out.println("3. Entered main_soundcapture"); /* initialise the audio data format; */ Date date = new Date(); String strFilename = dateFormat.format(date); File outputFile = new File(strFilename + ".wav"); AudioFormat audioFormat = new AudioFormat( AudioFormat.Encoding.PCM_SIGNED, 44100.0F, 16, 2, 4, 44100.0F, false); /* initialise audio file type;*/ AudioFileFormat.Type targetType = AudioFileFormat.Type.WAVE; System.out.println("4. Audio/file formats initialised"); /* initialise new target data line, if requesting the line was successful then open the target data line;*/ DataLine.Info info = new DataLine.Info(TargetDataLine.class, audioFormat); TargetDataLine targetDataLine = null; try { targetDataLine = (TargetDataLine) AudioSystem.getLine(info); targetDataLine.open(audioFormat); } catch (LineUnavailableException e) { out("unable to get a recording line"); e.printStackTrace(); System.exit(1); } System.out.println("5. TargetDataline grabbed"); m_line = targetDataLine; m_audioInputStream = new AudioInputStream(targetDataLine); m_targetType = targetType; m_outputFile = outputFile; out("Press ENTER to start the recording."); try { System.in.read(); } catch (IOException e) { e.printStackTrace(); } start(); out("Recording..."); out("Press ENTER to stop the recording."); try { System.in.read(); } catch (IOException e) { e.printStackTrace(); } /* Here, the recording is actually stopped. */ stopRecording(); out("Recording stopped."); } private static void out(String strMessage) { System.out.println(strMessage); } public void start() { System.out.println("Started recording"); m_line.start(); run(); } public void stopRecording() { m_line.stop(); m_line.close(); } // CRASHES HERE public void run() { try { System.out.println("Try audiosystem.write"); AudioSystem.write( m_audioInputStream, m_targetType, m_outputFile); } catch (IOException e) { System.out.println("Catch IOException"); e.printStackTrace(); } System.out.println("Recording complete"); } }Last edited by B_Tank88; 01-31-2012 at 01:10 PM.
Similar Threads
-
Need a Help to write a program like write a word for the given number
By manideep.d132 in forum New To JavaReplies: 7Last Post: 11-30-2011, 06:58 PM -
help returning a min value
By Meta in forum New To JavaReplies: 7Last Post: 04-11-2011, 12:28 AM -
Accessing AudioSystem getMixerInfo()??
By Jlister76 in forum New To JavaReplies: 6Last Post: 02-25-2011, 12:04 PM -
Help with returning
By Da1dmoney in forum EclipseReplies: 3Last Post: 12-15-2010, 02:38 AM -
Can't hear the wav file im playing :( (using AudioSystem)
By Addez in forum New To JavaReplies: 3Last Post: 03-03-2010, 09:51 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks