在java中播放.wav文件 [英] Play .wav file in java
本文介绍了在java中播放.wav文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有代码来播放.wav文件。但是,似乎没有任何实际的音频播放。该程序甚至在最后打印出小测试的东西。我似乎无法弄清楚为什么它不会产生任何声音。
提前感谢您的帮助。
我尝试过:
I have the code to play a .wav file working. however, there doesn't seem to be any actual audio playing. The program even prints the little test thing at the end. I can't seem to figure out why it won't produce any sound.
Thanks for the help in advance.
What I have tried:
import java.applet.*;
import java.io.File;
import java.net.*;
public class playAudio{
public static void main(String args[]) {
try {
AudioClip clip = Applet.newAudioClip(new URL("file:/------"));
clip.play();
System.out.println("test");
}
catch (MalformedURLException murle) {
System.out.println(murle);
}
}
}
推荐答案
试试这个
Try this
public static void play(String filename)
{
try
{
Clip clip = AudioSystem.getClip();
clip.open(AudioSystem.getAudioInputStream(new File(filename)));
clip.start();
}
catch (Exception exc)
{
exc.printStackTrace(System.out);
}
}
这篇关于在java中播放.wav文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文