首页 热点资讯 义务教育 高等教育 出国留学 考研考公

求一个简单java播放wav音频程序

发布网友

我来回答

2个回答

热心网友

/**
* 播放音乐
*
* @param mp3Path
* @param repeat
*/
public static void playSound(final String mp3Path, final int repeat) {

new Thread(new Runnable() {

@Override
public void run() {

if (mp3Path.endsWith("mp3")) {
// TODO Auto-generated method stub
MP3Player mp3 = new MP3Player(mp3Path);
int ccc = 0;
while (ccc < repeat) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ccc++;
mp3.play();
}
} else {
try {
// .wav 文件放在java project 下面
//System.getProperty("user.dir") + File.separator+ "ring.wav"
System.out.println(mp3Path);
FileInputStream fileau = new FileInputStream(
mp3Path);
AudioStream as = new AudioStream(fileau);
int ccc = 0;
while (ccc < repeat) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ccc++;
AudioPlayer.player.start(as);
}

} catch (Exception e) {
e.printStackTrace();
}
}
}
}).start();

}

sun audio jar下载 需要自己下载

热心网友

import java.applet.*;
import java.io.*;
import java.net.*;

public class AudioPlay {
URL radio = null;
AudioClip clip = null;
File file = null;

public static void main(String[] args) throws MalformedURLException {
new AudioPlay().play("C:\\a.wav");
}

public void play(String path) throws MalformedURLException {
file = new File(path);
radio = file.toURL();
clip = Applet.newAudioClip(radio);
clip.play();
}}追问无法播放声音 也没有异常

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com