Results 1 to 10 of 10
Thread: Problem code audio
- 10-27-2012, 02:01 PM #1
Member
- Join Date
- Jul 2012
- Posts
- 7
- Rep Power
- 0
Problem code audio
Hi, my problem code my class audiotool.java
warnings:
my code experiment for jdk 7.07update:PHP Code:D:\java>javac AudioTool.java AudioTool.java:5: warning: WaveFileWriter is internal proprietary API and may be removed in a future release import com.sun.media.sound.WaveFileWriter; ^ AudioTool.java:105: warning: WaveFileWriter is internal proprietary API and may be removed in a future release final AudioFileWriter afw = new WaveFileWriter(); ^ 2 warnings
Sorry , my languagge italian.Java Code:import java.io.*; import javax.sound.sampled.*; import javax.sound.sampled.spi.AudioFileWriter; import com.sun.media.sound.WaveFileWriter; public class AudioTool { private static final long serialVersionUID = 1L; protected boolean running; ByteArrayOutputStream out; /** * Catturazione Audio - CaptureAudio */ public void captureAudio() { try { final AudioFormat format = getFormat(); DataLine.Info info = new DataLine.Info(TargetDataLine.class, format); final TargetDataLine line = (TargetDataLine)AudioSystem.getLine(info); line.open(format); line.start(); Runnable runner = new Runnable() { int bufferSize = (int)format.getSampleRate() * format.getFrameSize(); byte buffer[] = new byte[bufferSize]; public void run() { out = new ByteArrayOutputStream(); running = true; try { while (running) { int count = line.read(buffer, 0, buffer.length); if (count > 0) { out.write(buffer, 0, count); } } out.close(); line.close(); } catch (IOException e) { System.err.println("I/O problems: " + e); System.exit(-1); } } }; Thread captureThread = new Thread(runner); captureThread.start(); } catch (LineUnavailableException e) { System.err.println("Line unavailable: " + e); System.exit(-2); } } /** * Suona Audio - playAudio */ public void playAudio() { try { byte audio[] = out.toByteArray(); InputStream input = new ByteArrayInputStream(audio); final AudioFormat format = getFormat(); final AudioInputStream ais = new AudioInputStream(input, format, audio.length / format.getFrameSize()); DataLine.Info info = new DataLine.Info(SourceDataLine.class, format); final SourceDataLine line = (SourceDataLine) AudioSystem.getLine(info); line.open(format); line.start(); Runnable runner = new Runnable() { int bufferSize = (int) format.getSampleRate() * format.getFrameSize(); byte buffer[] = new byte[bufferSize]; public void run() { try { int count; while ((count = ais.read( buffer, 0, buffer.length)) != -1) { if (count > 0) { line.write(buffer, 0, count); } } line.drain(); line.stop(); line.close(); } catch (IOException e) { System.err.println("I/O problems: " + e); System.exit(-3); } } }; Thread playThread = new Thread(runner); playThread.start(); } catch (LineUnavailableException e) { System.err.println("Line unavailable: " + e); System.exit(-4); } } /** * Salva Audio - saveAudio (Path). */ public void saveAudio(String Path) { File file = new File(Path); try { byte audio[] = out.toByteArray(); InputStream input = new ByteArrayInputStream(audio); final AudioFormat format = getFormat(); final AudioInputStream ais = new AudioInputStream(input, format, audio.length / format.getFrameSize()); final AudioFileWriter afw = new WaveFileWriter(); afw.write(ais, AudioFileFormat.Type.WAVE, file ); ais.close(); } catch (IOException e) { System.err.println("Impossibile salvare il file '"+file+"': " + e); System.exit(-4); } } /** * Configurazione Audio - */ private AudioFormat getFormat() { float sampleRate = 8000; int sampleSizeInBits = 8; int channels = 1; boolean signed = true; boolean bigEndian = true; return new AudioFormat(sampleRate,sampleSizeInBits, channels, signed, bigEndian); } }
My User system Windows 7 64bit ..
Help help.
- 10-27-2012, 03:26 PM #2
Re: Problem code audio
Moved from Other IDEs.
What exactly is your question? Evidently your code compiles without errors; does it or doesn't it run without errors?
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 10-27-2012, 03:57 PM #3
Member
- Join Date
- Jul 2012
- Posts
- 7
- Rep Power
- 0
Re: Problem code audio
my problem .. remove to warnings for code.. solution?
thanks.
- 10-27-2012, 07:13 PM #4
Re: Problem code audio
If you need to use a com.sun... proprietary class, then no, you can't remove the warnings.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 10-27-2012, 07:36 PM #5
Member
- Join Date
- Jul 2012
- Posts
- 7
- Rep Power
- 0
- 10-27-2012, 08:01 PM #6
Member
- Join Date
- Jul 2012
- Posts
- 7
- Rep Power
- 0
Re: Problem code audio
ok, problem 1 ..:
info warning:Java Code:import javax.sound.sampled.*; import javax.sound.sampled.spi.*; import com.sun.media.sound.*; import java.lang.*; import java.io.*; public class AudioTool { private static final long serialVersionUID = 1L; protected boolean running; ByteArrayOutputStream out; /** * Catturazione Audio - CaptureAudio */ public void captureAudio() { try { final AudioFormat format = getFormat(); DataLine.Info info = new DataLine.Info(TargetDataLine.class, format); final TargetDataLine line = (TargetDataLine)AudioSystem.getLine(info); line.open(format); line.start(); Runnable runner = new Runnable() { int bufferSize = (int)format.getSampleRate() * format.getFrameSize(); byte buffer[] = new byte[bufferSize]; public void run() { out = new ByteArrayOutputStream(); running = true; try { while (running) { int count = line.read(buffer, 0, buffer.length); if (count > 0) { out.write(buffer, 0, count); } } out.close(); line.close(); } catch (IOException e) { System.err.println("I/O problems: " + e); System.exit(-1); } } }; Thread captureThread = new Thread(runner); captureThread.start(); } catch (LineUnavailableException e) { System.err.println("Line unavailable: " + e); System.exit(-2); } } /** * Suona Audio - playAudio */ public void playAudio() { try { byte audio[] = out.toByteArray(); InputStream input = new ByteArrayInputStream(audio); final AudioFormat format = getFormat(); final AudioInputStream ais = new AudioInputStream(input, format, audio.length / format.getFrameSize()); DataLine.Info info = new DataLine.Info(SourceDataLine.class, format); final SourceDataLine line = (SourceDataLine) AudioSystem.getLine(info); line.open(format); line.start(); Runnable runner = new Runnable() { int bufferSize = (int) format.getSampleRate() * format.getFrameSize(); byte buffer[] = new byte[bufferSize]; public void run() { try { int count; while ((count = ais.read( buffer, 0, buffer.length)) != -1) { if (count > 0) { line.write(buffer, 0, count); } } line.drain(); line.stop(); line.close(); } catch (IOException e) { System.err.println("I/O problems: " + e); System.exit(-3); } } }; Thread playThread = new Thread(runner); playThread.start(); } catch (LineUnavailableException e) { System.err.println("Line unavailable: " + e); System.exit(-4); } } /** * Salva Audio - saveAudio (Path). */ public void saveAudio(String Path) { File file = new File(Path); try { byte audio[] = out.toByteArray(); InputStream input = new ByteArrayInputStream(audio); final AudioFormat format = getFormat(); final AudioInputStream ais = new AudioInputStream(input, format, audio.length / format.getFrameSize()); final AudioFileWriter afw = new WaveFileWriter(); afw.write(ais, AudioFileFormat.Type.WAVE, file ); ais.close(); } catch (IOException e) { System.err.println("Impossibile salvare il file '"+file+"': " + e); System.exit(-4); } } /** * Configurazione Audio - */ private AudioFormat getFormat() { float sampleRate = 8000; int sampleSizeInBits = 8; int channels = 1; boolean signed = true; boolean bigEndian = true; return new AudioFormat(sampleRate,sampleSizeInBits, channels, signed, bigEndian); } }
help my solution?Java Code:D:\java>javac AudioTool.java AudioTool.java:106: warning: WaveFileWriter is internal proprietary API and may be removed in a future release final AudioFileWriter afw = new WaveFileWriter(); ^ 1 warning D:\java>
thanks
- 10-27-2012, 09:28 PM #7
Re: Problem code audio
I've already answered that.
Did you write the code or is this something you found and copied without understanding it?
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 10-28-2012, 12:56 PM #8
Member
- Join Date
- Jul 2012
- Posts
- 7
- Rep Power
- 0
Re: Problem code audio
My code works on java 2.6. With JAVA 2.7 mi says those warnings.
help?
- 10-28-2012, 04:18 PM #9
- 11-06-2012, 01:16 PM #10
Member
- Join Date
- Jul 2012
- Posts
- 7
- Rep Power
- 0
Similar Threads
-
Audio conferencing using JMF
By sathishkumar in forum Advanced JavaReplies: 0Last Post: 03-10-2011, 03:02 PM -
C server code - Java CLient Code _ TCP Connection Problem
By rmd22 in forum NetworkingReplies: 0Last Post: 02-21-2011, 11:50 AM -
Capture audio problem
By Ang3lo in forum New To JavaReplies: 0Last Post: 01-10-2011, 10:57 PM -
Can anyone see the problem with my code? problem understanding switch (newbish)
By keith in forum New To JavaReplies: 9Last Post: 09-21-2010, 04:15 PM -
Audio Recorder
By elizabeth in forum Java AppletsReplies: 1Last Post: 08-06-2007, 09:21 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks