使用Java从URL记录文件音频

时间:2017-09-06 10:45:07

标签: java audio-streaming

我正在尝试创建一个简单的脚本,它允许从URL记录文件(.wav)。我使用Java Sound API来做到这一点,但我找不到解决方案。

这是我的代码:

try{
        URLConnection conn = new URL("http://play.cadenaser.com/").openConnection();
        InputStream audioSrc = conn.getInputStream();

        //add buffer for mark/reset support
        InputStream bufferedIn = new BufferedInputStream(audioSrc);
        AudioInputStream audioStream = AudioSystem.getAudioInputStream(bufferedIn);

        OutputStream outstream = new FileOutputStream(new File("file.wav"));

        long t = System.currentTimeMillis();
        while (System.currentTimeMillis() - t <= 5000) {
            AudioSystem.write(audioStream, AudioFileFormat.Type.WAVE, outstream);
        }
        outstream.close();
    }
    catch(Exception e){
        System.out.print(e.getMessage());
    }

如果有人能帮助我,我会感激不尽 谢谢!

0 个答案:

没有答案