javasound

Error loading audio in java (illegal call to open() in interface Clip)

前提是你 提交于 2020-01-05 04:11:10
问题 I'm writing an new audio system for my game and i have come across this error and can not seem to find and solution anywhere, java.lang.IllegalArgumentException: illegal call to open() in interface Clip at com.sun.media.sound.DirectAudioDevice$DirectClip.implOpen(Unknown Source) at com.sun.media.sound.AbstractDataLine.open(Unknown Source) at com.sun.media.sound.AbstractDataLine.open(Unknown Source) This is the code i use to load and play my audio. private Clip load(String filename) { try { /

Java Use a Clip and a Try - with - resources block which results with no sound

巧了我就是萌 提交于 2020-01-04 14:14:50
问题 I am rewriting my AudioManager class for my school project and I encountered a problem. My professor told me to load all my resources with the Try-with-resources block instead of using try/catch ( See code below ). I am using the Clip class from javax.sound.sampled.Clip and everything works perfectly with my PlaySound(String path) method that uses try/catch/ if I don't close() the Clip. I know that if I close() the Clip I can't use it anymore. I have read the Oracle Docs for Clip and Try-with

How to cast from InputStream to AudioInputStream

做~自己de王妃 提交于 2020-01-03 19:32:06
问题 Is it possible to cast from an InputStream to an AudioInputStream? I want to play little sound files at certain events, so I made following SoundThread import java.io.*; import javax.sound.sampled.*; public class SoundThread implements Runnable{ private String filename; SoundThread(String filename) { this.filename = filename; } public void run() { try { InputStream in = ClassLoader.getSystemResourceAsStream("sounds/"+filename+".wav"); Clip clip = AudioSystem.getClip(); clip.open(

JAVA audio data streaming 0s

守給你的承諾、 提交于 2020-01-03 04:46:12
问题 I've been writing a short program to redirect audio from the line in/mic to to speakers. I'm just learning most of this, but my labors have yielded what seems to almost be a working model of what I want. However, when I print the TargetDataLine buffer, it prints all 0s as if it was connected and streaming, but can't hear my input. At this point, I've studied most of the sampled package content and what was available online in forums, tutorials, and other people's code, and due to the

Can anyone tell me why my volume control doesn't work?

别说谁变了你拦得住时间么 提交于 2020-01-03 04:32:06
问题 Can anyone tell me why my volume control doesn't work...? import java.io.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.sound.sampled.*; import javax.swing.event.*; /*<Applet code="kkk" height=400 width=400></Applet>*/ public class kkk extends JComponent { static File f1; int prog; static JFrame jf; int al; JLabel time; Timer tr; Button b; int pos=0; Clip c; AudioInputStream a; JSlider s; public static void main(String args[]) { f1=new File("mm.wav"); jf=new

What exactly does AudioInputStream.read method return?

心不动则不痛 提交于 2020-01-03 03:13:11
问题 I have some problems finding out, what I actually read with the AudioInputStream . The program below just prints the byte-array I get but I actually don't even know, if the bytes are actually the samples, so the byte-array is the audio wave . File fileIn; AudioInputStream audio_in; byte[] audioBytes; int numBytesRead; int numFramesRead; int numBytes; int totalFramesRead; int bytesPerFrame; try { audio_in = AudioSystem.getAudioInputStream(fileIn); bytesPerFrame = audio_in.getFormat()

Turning the computer volume up/down with Java?

风流意气都作罢 提交于 2020-01-01 14:38:19
问题 I want to turn the master volume of the computer up and down (100%/0%), with just a command. I saw that I could use FloatControl , but I'm not sure how to use it. 回答1: Have at look at using JavaSound to control the master volume. From the link: Mixer.Info [] mixers = AudioSystem.getMixerInfo(); System.out.println("There are " + mixers.length + " mixer info objects"); for (Mixer.Info mixerInfo : mixers) { System.out.println("Mixer name: " + mixerInfo.getName()); Mixer mixer = AudioSystem

How do I play two sounds at once?

瘦欲@ 提交于 2019-12-31 04:11:06
问题 When I try to play two sounds at once in an applet, it won't work. I'm using AudioClip s. Is it even possible to play two sounds at once in an applet? 回答1: Since Java 1.3+, use the Clip class of the Java Sound API. It is similar to the applet based AudioClip class, but better. E.G. adapted from the one shown on the Java Sound info. page. import java.net.URL; import javax.swing.*; import javax.sound.sampled.*; public class LoopSounds { public static void main(String[] args) throws Exception {

Audio Clip won't loop continuously

谁说我不能喝 提交于 2019-12-29 07:01:52
问题 Can anyone point me in the right direction as to why this code will not play this audio clip continuously? It plays it once and stops. final Clip clip = AudioSystem.getClip(); final AudioInputStream inputStream = AudioSystem.getAudioInputStream(new File("Alarm_Police.wav")); clip.open(inputStream); clip.loop(Clip.LOOP_CONTINUOUSLY); 回答1: If you are running a bigger application, this answer may not apply. But for a simple test with only that piece of code, this may help: Clip.loop() starts it

Panel Fails to Show Up Concurrently with Sound File In Java Swing

走远了吗. 提交于 2019-12-25 14:23:36
问题 After the dialog of my game finishes, a scary pop-up is suppose to show with a screeching noise. When I click the button (BPanel), the picture appears "corrupted" until the sound file finishes playing. After the scream finishes, the picture pops out. Is it possible to simply synchronize the two together? Note that the problem is happening in the Woc class where Scaryface.png and the Sound class is used. Main method: import javax.swing.*; import java.awt.*; import java.awt.event.*; public