InputStream in = new FileInputStream(fileName);
AudioStream audio = new AudioStream(in); 
AudioData data = audio.getData(); 
ContinuousAudioDataStream conAudio = new ContinuousAudioDataStream (data);
AudioPlayer.player.start (conAudio);

解决方案 »

  1.   

    我来补充另一种方法,用AudioClip方法AudioClip audio;
    String audioName="1.wav";
    audio.play();
    audio.loop();
    audio.stop();
      

  2.   

    Killme2008(Java-Dog),你的程序也不对啊。import sun.audio.*;
    import java.io.*;public class As
    {
     public static void main(String args[])
     {
     
     try {
      InputStream in = new FileInputStream("c:\\1.au");
    AudioStream audio = new AudioStream(in); 
    AudioData data = audio.getData(); 
    ContinuousAudioDataStream conAudio = new ContinuousAudioDataStream (data);
    AudioPlayer.player.start (conAudio); }
     catch (Exception e) {System.out.println(e);}
     }
    }
    运行的时候也是报的这个错误:
    java.io.IOException: could not create audio stream from input stream
    Press any key to continue...
    好像AudioClip是用于Applet里面的吧。我的是JFrame。
      

  3.   

    一个很讨人厌的家伙写的,不过可以用!import java.applet.Applet;
    import java.applet.AudioClip;
    import java.io.File;
    import java.io.IOException;
    import java.net.URL;public class AppletSound
    {
        /**类静态变量*/
        private static AppletSound appletSound = null;
        /**声音文件路径及名称静态变量*/
        private static URL audioURL = null;
        /**声音静态变量*/
        private static AudioClip audioWAV = null;    /**
         * 构建器
         * <p>加载声音文件。
         * @throws IOException
         */
        private AppletSound() throws IOException
        {
            try {
                File file = new File("xxx.wav")
                audioURL = new URL("file:///" + file.getAbsoluteFile());
                audioWAV = Applet.newAudioClip(audioURL);
            } catch (IOException ie) {
              throw ie;
            }
        }      private static AppletSound getInstance() throws IOException
        {
            if (null == appletSound) {
                appletSound = new AppletSound();
            }
            return appletSound;
        }    /**
         * 播放声音
         * @throws IOException
         */
        public static void play() throws IOException
        {
            getInstance().audioWAV.play();
        }    /**
         * 循环播放
         * @throws IOException
         */
        public static void loop() throws IOException
        {
            getInstance().audioWAV.loop();
        }    /**
         * 停止播放
         * @throws IOException
         */
        public static void stop() throws IOException
        {
            getInstance().audioWAV.stop();
        }
    }
      

  4.   

    xiaoyusong(加肥猫)
    你指的
    一个很讨人厌的家伙说的是张天奢嘛?
      

  5.   

    楼上的File file = new File("xxx.wav");这一句话编译有错误的啊。
    错误信息:
    C:\Documents and Settings\Administrator\桌面\AppletSound.java:24: illegal character: \65288
                File file = new File("1.au");
                                    ^
    1 error
      

  6.   

    xiaoyusong(加肥猫) ,你写的程序是用在Applet里面的吧,我现在要用在JFrame里面的啊。有谁可以帮我解决吗?
      

  7.   

    参考项--好象AU和WAV是不同的文件格式,要转换一下
    另外可以先用AIS,再转换成AS试一下
    AudioInputStream ais= new AudioStream(in);