求一个简单java播放wav音频程序 5
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下载 需要自己下载
* 播放音乐
*
* @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();
}}
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();
}}
追问
无法播放声音 也没有异常
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询