javasound

Java Applet: Basic Drum Set

蓝咒 提交于 2019-12-02 06:32:08
I am trying to program an applet that has four buttons, all of which play a short audio file. The goal is to try and have the user successfully click the buttons any number of times, therefore creating a beat. Here is my attempt: import java.awt.*; import java.applet.*; import java.awt.event.*; import javax.swing.*; public class drumKit extends JApplet { private JButton snareButton; private JButton hiHatButton; private JButton bassButton; private JButton cymbalsButton; private AudioClip snare; private AudioClip hiHat; private AudioClip bass; private AudioClip cymbals; public void init() {

Error playing AudioInputStream

时光毁灭记忆、已成空白 提交于 2019-12-02 05:42:19
问题 I want to create 2 JMenuItem that can start and stop the background audio. Here is my code : public class MainClass extends JFrame { private AudioInputStream audioInputStream; private Clip clip; public MainClass(String title) { try { audioInputStream = AudioSystem.getAudioInputStream(new File("Background.wav")); clip = AudioSystem.getClip(); clip.loop(Clip.LOOP_CONTINUOUSLY); clip.open(audioInputStream); } catch(Exception e) { System.out.println("Error with playing sound."); e.printStackTrace

Error playing AudioInputStream

帅比萌擦擦* 提交于 2019-12-02 01:38:51
I want to create 2 JMenuItem that can start and stop the background audio. Here is my code : public class MainClass extends JFrame { private AudioInputStream audioInputStream; private Clip clip; public MainClass(String title) { try { audioInputStream = AudioSystem.getAudioInputStream(new File("Background.wav")); clip = AudioSystem.getClip(); clip.loop(Clip.LOOP_CONTINUOUSLY); clip.open(audioInputStream); } catch(Exception e) { System.out.println("Error with playing sound."); e.printStackTrace(); } } public void startSound() { clip3.start(); settingSubMenuItem1.setEnabled(false);

Why does Java Sound behave differently when I run from a .jar?

家住魔仙堡 提交于 2019-12-02 00:21:31
问题 The play method below is from a class which, upon instantiation, reads a .wav file into a byte array called data , and stores the sound format in an AudioFormat object called format . I have a program that calls play from a java.util.Timer . When I go into the folder with all the relevant .class files and I run the program using the command java MainClass , everything works as expected. However, when I put all the .class files in an executable .jar and run the program using the command java

Why does Java Sound behave differently when I run from a .jar?

╄→尐↘猪︶ㄣ 提交于 2019-12-01 22:38:14
The play method below is from a class which, upon instantiation, reads a .wav file into a byte array called data , and stores the sound format in an AudioFormat object called format . I have a program that calls play from a java.util.Timer . When I go into the folder with all the relevant .class files and I run the program using the command java MainClass , everything works as expected. However, when I put all the .class files in an executable .jar and run the program using the command java -jar MyProgram.jar , sounds played using the play method are cut off after something like 50 to 150 ms.

Java Sound: devices found when run in IntelliJ, but not in SBT

假如想象 提交于 2019-12-01 20:24:38
I'm trying to to use Java Sound API in a Scala SBT-managed project. Here is a toy app that plays a note. import javax.sound.midi._ object MyMain extends App { val infos = MidiSystem.getMidiDeviceInfo() println( "[DEBUG] midi devices found: " + infos.length ) val myMsg = new ShortMessage; // Start playing the note Middle C (60), // moderately loud (velocity = 93). myMsg.setMessage(ShortMessage.NOTE_ON, 0, 60, 93); val timeStamp = -1; val rcvr : Receiver = MidiSystem.getReceiver(); rcvr.send(myMsg, timeStamp); readChar() // give time to play note } When I execute run in SBT, I get the javax

Playing a Sound Effect in Java

南楼画角 提交于 2019-12-01 14:04:45
I'm trying to do the equivalent of this line of code, except substituting a small mp3 file for the system beep: Toolkit.getDefaultToolkit().beep(); I have an mp3 file that has a little sound effect that I want to play. Is this a relatively easy thing to do? Can somebody show me the code to do this? You could use MediaPlayer to play the sound. Here is what I usually use for all my audio. public class APP extends Activity { //ADD THIS LINE AND IMPORT MediaPlayer MediaPlayer btnClick; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R

Why am I getting this LineUnavailableException?

瘦欲@ 提交于 2019-12-01 13:50:11
I keep getting the LineUnavailableException on line 34 of my code: https://www.refheap.com/21223 The error reads as javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, mono, 2 bytes/frame, little-endian not supported. . I'm creating multiple instances of the Sound class (implemented in my refheap paste). It seems that the first instances have no problem. But when I start making new instances of Sound objects using the same audio file then I start getting this error. Any idea how to fix it? EIDT: I think the ByteArrayInputStream idea from this question

Playing a Sound Effect in Java

元气小坏坏 提交于 2019-12-01 12:53:21
问题 I'm trying to do the equivalent of this line of code, except substituting a small mp3 file for the system beep: Toolkit.getDefaultToolkit().beep(); I have an mp3 file that has a little sound effect that I want to play. Is this a relatively easy thing to do? Can somebody show me the code to do this? 回答1: You could use MediaPlayer to play the sound. Here is what I usually use for all my audio. public class APP extends Activity { //ADD THIS LINE AND IMPORT MediaPlayer MediaPlayer btnClick;

Is there a way of recording audio of streaming broadcast from a webpage?

余生颓废 提交于 2019-12-01 10:47:23
问题 I'm looking to create webpage for record streaming audio from source (like online radio). At first I thought of doing something like recording from speakers, but solutions like flash, java and javascript refer to recording from microphone and not directly from speakers. Other alternative is to try capturing the streaming and save to local file, but I couldn't find any way of doing so from a webpage. Solutions like this refer to iPad platfrom, and not suitable for standard webpage. Any help