java播放声音出现错误!
importjava.io.BufferedInputStream;importjava.io.File;importjava.io.FileInputStream;im...
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import sun.audio.AudioPlayer;
import sun.audio.AudioStream;
public class E {
public static void main(String[] args){
BombMusic b=new BombMusic();
new Thread(b).start();
}
/**
*该方法为音频流缓冲方法,在调用音频播放线程时调用
*/
public BufferedInputStream loadBomb(){
BufferedInputStream bufbomb = null;
try{
File dir = new File("./Sounds/"); //所要播放文件的路径
File fObject = new File(dir,"1.wma"); //音频名
FileInputStream file = new FileInputStream(fObject);
bufbomb = new BufferedInputStream(file);
}catch(IOException e) {
System.out.println(e.getMessage());
}
return bufbomb;
}
/**
* 缓冲完毕的核爆音频播放线程
*/
}
class BombMusic implements Runnable{ //通过流读取声音文件
BufferedInputStream buf;
public void run(){
buf = new E().loadBomb();
try{
AudioStream audio = new AudioStream(buf);
AudioPlayer.player.start(audio);
}catch(IOException e){
System.out.println(e.getMessage());
}
}
}
最后抛出异常:could not create audio stream from input stream。文件是存在的,求大神回答,要怎么办。 展开
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import sun.audio.AudioPlayer;
import sun.audio.AudioStream;
public class E {
public static void main(String[] args){
BombMusic b=new BombMusic();
new Thread(b).start();
}
/**
*该方法为音频流缓冲方法,在调用音频播放线程时调用
*/
public BufferedInputStream loadBomb(){
BufferedInputStream bufbomb = null;
try{
File dir = new File("./Sounds/"); //所要播放文件的路径
File fObject = new File(dir,"1.wma"); //音频名
FileInputStream file = new FileInputStream(fObject);
bufbomb = new BufferedInputStream(file);
}catch(IOException e) {
System.out.println(e.getMessage());
}
return bufbomb;
}
/**
* 缓冲完毕的核爆音频播放线程
*/
}
class BombMusic implements Runnable{ //通过流读取声音文件
BufferedInputStream buf;
public void run(){
buf = new E().loadBomb();
try{
AudioStream audio = new AudioStream(buf);
AudioPlayer.player.start(audio);
}catch(IOException e){
System.out.println(e.getMessage());
}
}
}
最后抛出异常:could not create audio stream from input stream。文件是存在的,求大神回答,要怎么办。 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询