javasound

I want to make a java program in which there is a combobox which displays the titles of all the files available in a folder

孤者浪人 提交于 2019-12-13 04:03:43
问题 I actually want a JFrame in which there is a combobox. There is a folder which has 3 sound files named: sound1.wav sound2.wav sound3.wav The combobox should display these 3 file titles and when I click one of them it plays that sound file. 回答1: You could simply search the folder and populate the combobox with the values (Example: http://www.exampledepot.com/egs/java.io/GetFiles.html). To play the soundfiles you may want to look here: How can I play sound in Java? 回答2: You can use .listFiles()

Concatenation of two WAV files failed

狂风中的少年 提交于 2019-12-12 16:30:03
问题 I have this simple code to concatenate two wav files. Its pretty simple and the code runs without any errors. But there is a problem with the output file. The output file generated does not play, and surprisingly its size is only 44 bytes whereas my input files "a.wav" & "b.wav" are both more than 500Kb in size. Here is my code: import java.io.File; import java.io.IOException; import java.io.SequenceInputStream; import javax.sound.sampled.AudioFileFormat; import javax.sound.sampled

Playing sound from a byte[] array

纵饮孤独 提交于 2019-12-12 13:14:17
问题 I've recieved a byte array from the server and I know that connects and sends perfectly. It's when I try and play the sound from the byte array. Here's what I have to play the sound. SourceDataLine speaker = null; try { DataLine.Info speakerInfo = new DataLine.Info(SourceDataLine.class, getAudioFormat(samplerate)); speaker = (SourceDataLine) AudioSystem.getLine(speakerInfo); } catch (LineUnavailableException e) { e.printStackTrace(); } int nBytesRead = 0; while (nBytesRead != -1) { if

Sound wave from TargetDataLine

ぐ巨炮叔叔 提交于 2019-12-12 09:14:48
问题 Currently I am trying to record a sound wave from a mic and display amplitude values in realtime in Java. I came across Targetdataline but I am having a bit of trouble understanding I get data from it. Sample code from Oracle states: line = (TargetDataLine) AudioSystem.getLine(info); line.open(format, line.getBufferSize()); ByteArrayOutputStream out = new ByteArrayOutputStream(); int numBytesRead; byte[] data = new byte[line.getBufferSize() / 5]; // Begin audio capture. line.start(); // Here,

Playing multiple byte arrays simultaneously in Java

Deadly 提交于 2019-12-12 07:14:27
问题 How can you play multiple (audio) byte arrays simultaneously? This "byte array" is recorded by TargetDataLine, transferred using a server. What I've tried so far Using SourceDataLine: There is no way to play mulitple streams using SourceDataLine, because the write method blocks until the buffer is written. This problem cannot be fixed using Threads, because only one SourceDataLine can write concurrently. Using the AudioPlayer Class: ByteInputStream stream2 = new ByteInputStream(data, 0, data

Get byte stream from an audio file?

偶尔善良 提交于 2019-12-12 04:54:47
问题 Is there any way to get audio stream from an audio file (wav file in particular) in Java? I am trying to get the stream of a particular interval i.e from startTime to endTime where startTime is not zero. For example, to get the audio stream from 5 sec to 10 sec (5 sec duration) of a 20 sec long audio file. How to do that? 回答1: You can do this with the standard Java sound library: javax.sound.sampled. Reading .wav files has been well covered here, as well as how to convert bytes to the

How to implement audio in a Java game?

自古美人都是妖i 提交于 2019-12-12 03:04:29
问题 I want to add audio to my java game, but I don't know how to put it in practice. By I've read, Java only plays wav files, but this files are too big. I've read a little about JLayer, but I actually need something like soundpool in android, for handle all in game effects. Do you know how to do it? I've to build a class that does it? 回答1: Here is some code for you that I've used in a game a while back using JLayer: public class MP3 { public void play(final InputStream in) { new Thread() {

Using JavaSounds from tomcat

泪湿孤枕 提交于 2019-12-12 01:37:37
问题 I'm trying to write a Java EE application that records sound from the input on the server. My code works fine when debuging, and running on the server as myself (both ubuntu) however when it's running from the web sever I get an exception: javax.sound.sampled.LineUnavailableException at org.classpath.icedtea.pulseaudio.PulseAudioMixer.openImpl(PulseAudioMixer.java:714) at org.classpath.icedtea.pulseaudio.PulseAudioMixer.openLocal(PulseAudioMixer.java:588) at org.classpath.icedtea.pulseaudio

Cannot play embedded sound in a jar file

Deadly 提交于 2019-12-12 00:35:02
问题 I am creating a software for personal use titled BatteryBeeper. It will remind me to charge the laptop when the charge is whatever I set to be reminded at. It is supposed to play a sound when the charge hits the set threshold. I had a look at the answer: sound not playing in jar and my AudioInputStream is constructed similar to what Jigar Joshi mentioned. However I get a null exception: java.lang.NullPointerException at com.sun.media.sound.SoftMidiAudioFileReader.getAudioInputStream(Unknown

Sound in java - Game freezes when playing sound

两盒软妹~` 提交于 2019-12-11 23:31:56
问题 Whenever I play a sound in my game, the thread freezes then continues after the sound has finished playing. Code for the sound engine: package com.kgt.platformer; import java.io.File; import java.io.IOException; 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.SourceDataLine; public class Sound {