获得';不支持的视距异常';在Java中从URL播放wav文件时

获得';不支持的视距异常';在Java中从URL播放wav文件时,java,audio,wav,Java,Audio,Wav,我必须从URL播放.wav文件,但得到不支持的FileException 下面是代码 public class LoopSound { public static void main(String[] args) throws Exception { HostnameVerifier hv = new HostnameVerifier() { @Override public boolean verify(String u

我必须从URL播放.wav文件,但得到
不支持的FileException

下面是代码

public class LoopSound {
    public static void main(String[] args) throws Exception {
        HostnameVerifier hv = new HostnameVerifier() {

            @Override
            public boolean verify(String urlHostName, SSLSession session) {
                System.out.println("Warning: URL Host: " + urlHostName
                        + " vs. " + session.getPeerHost());
                return true;
            }
        };
        // Now you are telling the JRE to trust any https server.
        // If you know the URL that you are connecting to then this should
        // not be a problem
        try {
            trustAllHttpsCertificates();
        } catch (Exception e) {
            System.out.println("Trustall" + e.getStackTrace());
        }
        HttpsURLConnection.setDefaultHostnameVerifier(hv);
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        URL url = new URL(
          "https://74.127.51.154/SiPbx/playback.php?access=subscriber&login=501%40mix&domain=mix.nms.mixnetworks.net&user=501&type=vmail&file=vm-20130109213353000125_netsapiens_com.wav&time=20130110170638&auth=de5dda39287604a88fc4b80c467e161d&submit=PLAY");
        Clip clip = AudioSystem.getClip();
        AudioInputStream ais = AudioSystem.
          getAudioInputStream( url );
        clip.open(ais);
        clip.loop(0);
        javax.swing.JOptionPane.
          showMessageDialog(null, "Close to exit!");
      }

     private static void trustAllHttpsCertificates() throws Exception {

            // Create a trust manager that does not validate certificate chains:

            javax.net.ssl.TrustManager[] trustAllCerts =

            new javax.net.ssl.TrustManager[1];

            javax.net.ssl.TrustManager tm = new TempTrustedManager();

            trustAllCerts[0] = tm;

            javax.net.ssl.SSLContext sc =

            javax.net.ssl.SSLContext.getInstance("SSL");

            sc.init(null, trustAllCerts, null);

            javax.net.ssl.HttpsURLConnection.setDefaultSSLSocketFactory(

            sc.getSocketFactory());

        }
     public static class TempTrustedManager implements
        javax.net.ssl.TrustManager, javax.net.ssl.X509TrustManager {
    public java.security.cert.X509Certificate[] getAcceptedIssuers() {
        return null;
    }

    public boolean isServerTrusted(
            java.security.cert.X509Certificate[] certs) {
        return true;
    }

    public boolean isClientTrusted(
            java.security.cert.X509Certificate[] certs) {
        return true;
    }

    public void checkServerTrusted(
            java.security.cert.X509Certificate[] certs, String authType)
            throws java.security.cert.CertificateException {
        return;
    }

    public void checkClientTrusted(
            java.security.cert.X509Certificate[] certs, String authType)
            throws java.security.cert.CertificateException {
        return;
    }
}
以下是获取的异常:

Exception in thread "main" javax.sound.sampled.UnsupportedAudioFileException: could not get audio input stream from input URL
    at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source)
    at LoopSound.main(LoopSound.java:35)
当我将上面的URL放在浏览器的地址栏中时,我可以下载该文件,但无法按语法播放。我怎样才能解决这个问题

编辑

我把链接改为

https://74.127.51.154/SiPbx/playback.php?access=subscriber&login=501%40mix&domain=mix.nms.mixnetworks.net&user=501&type=vmail&file=vm-20130109213353000125_netsapiens_com.wav&time=20130110170638&auth=de5dda39287604a88fc4b80c467e161d&submit=PLAY
现在,上述链接已放置在浏览器上,用于下载文件

但是当我现在执行程序时,得到了新的异常

Exception in thread "main" javax.sound.sampled.LineUnavailableException: line with format ULAW 8000.0 Hz, 8 bit, mono, 1 bytes/frame,  not supported.
    at com.sun.media.sound.DirectAudioDevice$DirectDL.implOpen(Unknown Source)
    at com.sun.media.sound.DirectAudioDevice$DirectClip.implOpen(Unknown Source)
    at com.sun.media.sound.AbstractDataLine.open(Unknown Source)
    at com.sun.media.sound.DirectAudioDevice$DirectClip.open(Unknown Source)
    at com.sun.media.sound.DirectAudioDevice$DirectClip.open(Unknown Source)
    at LoopSound.main(LoopSound.java:36)

提前感谢。

是一种容器格式(就像zip文件是许多不同文件的容器一样),因此没有实际的WAV音频格式(LPCM是最常见的)。在这种情况下,您的WAV包含一种称为“CCITT u-Law”的格式,该格式不受广泛支持(用于Cisco VoIP电话)。我还没有看到一个Java库可以读取它,但也许知道要查找什么会有所帮助。

下面的链接帮助了我,我现在可以播放wav文件了

编辑 根据Millimoose的评论,我正在粘贴上面链接中的一些代码以帮助其他人

我正在将wav文件的格式从
CCITT U-Law更改为PCM_SIGNED
,这是确切的wav格式

URL url = new URL(
                          "https://sssss/xxxxx/playback.php?access=subscriber&login=501%40mix&domain=mix.nms.mixnetworks.net&user=501&type=vmail&file=vm-20130109213243000082_mixnetworks_net.wav&time=20130110170638&auth=c43ff32546e126be9b895bbf225b2e75&submit=PLAY");
                 AudioInputStream fis =
                  AudioSystem.getAudioInputStream(url);
                 System.out.println("File AudioFormat: " + fis.getFormat());
                 AudioInputStream ais = AudioSystem.getAudioInputStream(
                  AudioFormat.Encoding.PCM_SIGNED,fis);
                 AudioFormat af = ais.getFormat();
                 System.out.println("AudioFormat: " + af.toString());

                 int frameRate = (int)af.getFrameRate();
                 System.out.println("Frame Rate: " + frameRate);
                 int frameSize = af.getFrameSize();
                 System.out.println("Frame Size: " + frameSize);

                 SourceDataLine line = AudioSystem.getSourceDataLine(af);
                 line.addLineListener(new MyLineListener());

                 line.open(af);
                 int bufSize = line.getBufferSize();
                 System.out.println("Buffer Size: " + bufSize);

                 line.start();

                 byte[] data = new byte[bufSize];
                 int bytesRead;

                 while ((bytesRead = ais.read(data,0,data.length)) != -1)
                     line.write(data,0,bytesRead);

                 line.drain();
                 line.stop();
                 line.close();

我们能帮忙吗?从浏览器调用URL时,我会看到一个登录屏幕。这有帮助吗?我应该投票,因为没有你们的解释,我不会尝试将u-law格式转换为wav文件的精确格式。谢谢你,伙计。这条线索是从大量猜测开始的,现在还不清楚解决方案是什么。你应该在你的答案中包括它对你有什么帮助,最好是它为什么有帮助。