可运行在Internet平台上的音频文件有HTML支持的WMIDI.JAVA支持的AU及RA.
另外试试看WAV格式的音乐文件.
这个不是很清楚..
sound=getAudioClip(getCodeBase(),"歌名.wav")
/*** 播放音乐
*
* @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下载 需要自己下载
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)