日期:2014-05-17  浏览次数:20853 次

java播放音频
各位老大,帮小弟个忙,小弟想用java在页面上播放音频(wav/amr/MID)格式。
小弟 用的是sun.audio的API
代码如下:FileInputStream fileau = new FileInputStream(new File(canshu));   
try{
    AudioStream as=new AudioStream(fileau);        AudioPlayer.player.start(as);   
}catch(Exception e){
e.printStackTrace();
}
但是在执行到红色时报错:java.io.EOFException
        at java.io.DataInputStream.readInt(Unknown Source)
        at com.sun.media.sound.WaveFileReader.getFMT(Unknown Source)
        at com.sun.media.sound.WaveFileReader.getAudioInputStream(Unknown Source
)
        at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source)
        at sun.audio.AudioStream.<init>(Unknown Source)
        at org.apache.jsp.manager.mms.yinpin_jsp._jspService(yinpin_jsp.java:64)

        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper
.java:393)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:3
20)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:206)
        at com.psb.filter.chinese.doFilter(chinese.java:19)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:230)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV