public static synchronized void playWav(final InputStream url) { //Plays wav, from Inputstream!
new Thread(new Runnable() {
public void run() {
try {
Clip clip = AudioSystem.getClip();
AudioInputStream inputStream = AudioSystem.getAudioInputStream(url);
clip.open(inputStream);
sounds.put(sounds.size() + 1,clip);
clip.start();
} catch (Exception e) {
e.printStackTrace();
}
}
},"SoundHandler").start();
}
java类javax.sound.sampled.AudioInputStream的实例源码
SoundHandler.java 文件源码
项目:PhySIX
阅读 16
收藏 0
点赞 0
评论 0
SoundHandler.java 文件源码
项目:PhySIX
阅读 16
收藏 0
点赞 0
评论 0
public static synchronized void playWav(File file) {
new Thread(new Runnable() {
public void run() {
try {
Clip clip = AudioSystem.getClip();
AudioInputStream inputStream = AudioSystem.getAudioInputStream(file);
clip.open(inputStream);
sounds.put(sounds.size() + 1,clip);
clip.start();
} catch (Exception e) {
e.printStackTrace();
}
}
},"SoundHandler").start();
}
SoftSynthesizer.java 文件源码
项目:openjdk-jdk10
阅读 27
收藏 0
点赞 0
评论 0
@Override
public int available() throws IOException {
AudioInputStream local_stream = stream;
if(local_stream != null)
return local_stream.available();
return 0;
}
SunFileReader.java 文件源码
项目:openjdk-jdk10
阅读 19
收藏 0
点赞 0
评论 0
@Override
public final AudioInputStream getAudioInputStream(final URL url)
throws UnsupportedAudioFileException, IOException {
final InputStream urlStream = url.openStream();
try {
return getAudioInputStream(new BufferedInputStream(urlStream));
} catch (final Throwable e) {
closeSilently(urlStream);
throw e;
}
}
JukeBox.java 文件源码
项目:BatBat-Game
阅读 16
收藏 0
点赞 0
评论 0
public static void load(String s, String n) {
if(clips.get(n) != null) return;
Clip clip;
try {
AudioInputStream ais =
AudioSystem.getAudioInputStream(
JukeBox.class.getResourceAsStream(s)
);
AudioFormat baseFormat = ais.getFormat();
AudioFormat decodeFormat = new AudioFormat(
AudioFormat.Encoding.PCM_SIGNED,
baseFormat.getSampleRate(),
16,
baseFormat.getChannels(),
baseFormat.getChannels() * 2,
baseFormat.getSampleRate(),
false
);
AudioInputStream dais = AudioSystem.getAudioInputStream(decodeFormat, ais);
clip = AudioSystem.getClip();
clip.open(dais);
clips.put(n, clip);
}
catch(Exception e) {
e.printStackTrace();
}
}
SFXClip.java 文件源码
项目:HawkEngine
阅读 17
收藏 0
点赞 0
评论 0
public SFXClip(String fileName)
{
File file = new File(fileName);
try
{
AudioInputStream stream = AudioSystem.getAudioInputStream(file);
this.clip = AudioSystem.getClip();
this.clip.open(stream);
}
catch(Exception e)
{
e.printStackTrace();
}
}
CommunicationHandler.java 文件源码
项目:POPBL_V
阅读 21
收藏 0
点赞 0
评论 0
/** Stop recoding and save if requested */
public void stopRecord() {
RecordDialog dialog = new RecordDialog(window, 420, 150);
if (dialog.getAcceptRecord()) {
Record newRecord = new Record(dialog.getName(), References.CHRONOMETER.getMinute(),
References.CHRONOMETER.getSecond(), References.CHRONOMETER.getHundredths());
References.RECORD_PANEL.getRecordModel().addElement(newRecord);
References.RECORD_PANEL.setUIStatus("stop");
References.CHRONOMETER.stop();
recordData = byteArrayOutputStream.toByteArray();
recordIS = new ByteArrayInputStream(recordData);
recordAIS = new AudioInputStream(recordIS, audioFormat, recordData.length / audioFormat.getFrameSize());
File wavFile = new File(newRecord.getRelativePath());
try {
AudioSystem.write(recordAIS, fileType, wavFile);
} catch (Exception e) {
e.printStackTrace();
}
} else {
if (transmissionON) {
References.RECORD_PANEL.setUIStatus("transmissionON");
}
}
if (References.KEYLISTENER_PANEL.isKeyIsDown()) {
References.KEYLISTENER_PANEL.setKeyIsDown();
References.KEYLISTENER_PANEL.getKeyReleasedAction().actionPerformed(null);
}
}
JavaSoundAudioClip.java 文件源码
项目:OpenJSharp
阅读 23
收藏 0
点赞 0
评论 0
private boolean loadAudioData(AudioInputStream as) throws IOException, UnsupportedAudioFileException {
if (DEBUG || Printer.debug)Printer.debug("JavaSoundAudioClip->openAsClip()");
// first possibly convert this stream to PCM
as = Toolkit.getPCMConvertedAudioInputStream(as);
if (as == null) {
return false;
}
loadedAudioFormat = as.getFormat();
long frameLen = as.getFrameLength();
int frameSize = loadedAudioFormat.getFrameSize();
long byteLen = AudioSystem.NOT_SPECIFIED;
if (frameLen != AudioSystem.NOT_SPECIFIED
&& frameLen > 0
&& frameSize != AudioSystem.NOT_SPECIFIED
&& frameSize > 0) {
byteLen = frameLen * frameSize;
}
if (byteLen != AudioSystem.NOT_SPECIFIED) {
// if the stream length is known, it can be efficiently loaded into memory
readStream(as, byteLen);
} else {
// otherwise we use a ByteArrayOutputStream to load it into memory
readStream(as);
}
// if everything went fine, we have now the audio data in
// loadedAudio, and the byte length in loadedAudioByteLength
return true;
}
WaveFloatFileWriter.java 文件源码
项目:jdk8u-jdk
阅读 19
收藏 0
点赞 0
评论 0
public int write(AudioInputStream stream, Type fileType, OutputStream out)
throws IOException {
checkFormat(fileType, stream);
if (stream.getFormat().isBigEndian())
stream = toLittleEndian(stream);
RIFFWriter writer = new RIFFWriter(new NoCloseOutputStream(out), "WAVE");
write(stream, writer);
int fpointer = (int) writer.getFilePointer();
writer.close();
return fpointer;
}
WaveFloatFileWriter.java 文件源码
项目:OpenJSharp
阅读 24
收藏 0
点赞 0
评论 0
private void checkFormat(AudioFileFormat.Type type, AudioInputStream stream) {
if (!Type.WAVE.equals(type))
throw new IllegalArgumentException("File type " + type
+ " not supported.");
if (!stream.getFormat().getEncoding().equals(Encoding.PCM_FLOAT))
throw new IllegalArgumentException("File format "
+ stream.getFormat() + " not supported.");
}