0

I am trying to play audio streaming using a simple java application. I have written the code but getting the following exception:

"javax.sound.sampled.UnsupportedAudioFileException: could not get audio input stream from input URL"

Not sure what I am doing wrong. Please help. Thank you.

Pasted below is my code:

    public static void main(String[] args) {
        URL url = null;

        try {
            url = new URL("http://stream.xmission.com:8000/kcpw");
            AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(url);
            Clip clip = AudioSystem.getClip();
            clip.open(audioInputStream);
            clip.start();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (UnsupportedAudioFileException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (LineUnavailableException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
  • Possible duplicate of [Java Wav file Error (javax.sound.sampled.UnsupportedAudioFileException: could not get audio input stream from input file)](https://stackoverflow.com/questions/14943962/java-wav-file-error-javax-sound-sampled-unsupportedaudiofileexception-could-no) – Bhavay Anand Jul 08 '19 at 21:17
  • @Bhavay Anand I looked at that post before posting but couldn't fix this issue of mine so if you think it might be a possible duplicate, can you suggest me on how to fix it? Thank you for the comment. – techiedev369 Jul 08 '19 at 21:25
  • 1
    Not a duplicate. The source files in the two cases are quite different. The linked question is a local .wav. In this question, the url is not pointing to a .wav but an html location that can stream audio. I don't know how such a thing is handled. My inclination would be to download a copy of the source audio file and use the copy as a local resource. – Phil Freihofner Jul 09 '19 at 04:56
  • #techiedev369 I might go as far as saying this could be an mp3 stream or worse an AAC!!! mp3 is not because I checked but AAC dont have the time to check see the library that reads aac – gpasch Jul 10 '19 at 08:36
  • I was able to make it work using Jl player of javazoom. Here is the link to the jar http://www.javazoom.net/javalayer/sources.html and here are some examples on how to use the jar https://www.programcreek.com/java-api-examples/?api=javazoom.jl.player.Player. Thank you all for the comments. – techiedev369 Jul 16 '19 at 02:12

0 Answers0