Results 1 to 17 of 17
  1. #1
    adrianb is offline Member
    Join Date
    Mar 2011
    Posts
    7
    Rep Power
    0

    Default Playing an audiostream in an applet.

    I want to play a continuous audiostream in an applet. The stream is provided by an Axis camera and it is retrieved by opening an URL which accesses a GGI file (<ip address>/blah-blah/receive.cgi. The incoming stream is in .au format.

    If I open a InputStream from this URL, then create an AudioInputStream from it, it throws an exception (could not get audio input stream from input stream ). I assume it is expecting a file not a stream from that URL. However, if I put the data in a file, I can play that file later as an AudioInputStream.

    Is there a way to play the stream in real-time? (maybe create a pipe file which is written from the camera and read by the AudioPlayer?)

    Any suggestions are welcome.

    Thank you

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  4. #4
    adrianb is offline Member
    Join Date
    Mar 2011
    Posts
    7
    Rep Power
    0

    Default

    Thanks for the answer.

    The following piece of code:

    try {
    url = new URL("http://192.168.3.8/axis-cgi/audio/receive.cgi?httptype=singlepart");
    is = url.openStream();
    ais = AudioSystem.getAudioInputStream(is);
    } catch (UnsupportedAudioFileException ex) {
    Logger.getLogger(AUPlayer.class.getName()).log(Lev el.SEVERE, null, ex);
    } catch (IOException ex) {
    Logger.getLogger(AUPlayer.class.getName()).log(Lev el.SEVERE, null, ex);
    }

    will catch the UnsupportedAudioFileException with the message: "could not get audio input stream from input stream"


    I also tried AudioClip and many other ideas. AudioClip doesn't throw an exception but doesn't play anything.

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  6. #6
    adrianb is offline Member
    Join Date
    Mar 2011
    Posts
    7
    Rep Power
    0

    Default

    SEVERE: null
    javax.sound.sampled.UnsupportedAudioFileException: could not get audio input stream from input stream
    at javax.sound.sampled.AudioSystem.getAudioInputStrea m(AudioSystem.java:1102)
    at auplayer.AUPlayer.init(AUPlayer.java:76)
    at sun.applet.AppletPanel.run(AppletPanel.java:424)
    at java.lang.Thread.run(Thread.java:619)

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  8. #8
    adrianb is offline Member
    Join Date
    Mar 2011
    Posts
    7
    Rep Power
    0

    Default

    So far I am in Netbeans debugger. I can connect and get the data stream from the camera.
    No permission issues at this point.

  9. #9
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  10. #10
    adrianb is offline Member
    Join Date
    Mar 2011
    Posts
    7
    Rep Power
    0

    Default

    I assume it comes from the exception I catch and report to the log, regarding the unsupported audio file.

    I said there are no permissions issues because it connects to the url, gets data from it and I can save it in a file and play later.

    I assume the problem is tha AudioSystem cannot play a stream, all the examples I found used a file stored on server, not a stream.

  11. #11
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    Quote Originally Posted by Eranga View Post
    Then what's this?

    That's the logger.
    The null is if the user doing the logging wants to add any additional message.

    For the OP, I'm not sure that that audio code will work with streamed audio. It seems to be designed for audio samples.

  12. #12
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by Tolls View Post
    That's the logger.
    The null is if the user doing the logging wants to add any additional message.

    For the OP, I'm not sure that that audio code will work with streamed audio. It seems to be designed for audio samples.
    Yeah I know that's from logger. But I want to point the OP why he came with a null.

  13. #13
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    It's the IDE:
    Java Code:
    Logger.getLogger(AUPlayer.class.getName()).log(Level.SEVERE, [B]null[/B], ex);
    Netbeans(?) default for when it adds a try/catch block automatically. Leaves it up to the developer to add something if they want I suppose.

  14. #14
    adrianb is offline Member
    Join Date
    Mar 2011
    Posts
    7
    Rep Power
    0

    Default

    As I said and Tolls said too, probably cannot play live streams.

    I kind of find some solution in the following way:

    url = new URL("http://192.168.3.8/axis-cgi/audio/receive.cgi?httptype=singlepart");
    is = url.openStream();

    while(true) {
    len = 0;
    offset = 0;
    while(len < FRAME_LEN) {
    n = is.read(b1, offset, FRAME_LEN - len);
    len += n;
    offset += n;
    }
    adata = new AudioData(b1);
    ads = new AudioDataStream(adata);
    AudioPlayer.player.start(ads);
    len = 0;
    offset = 0;
    while(len < FRAME_LEN) {
    n = is.read(b2, offset, FRAME_LEN - len);
    len += n;
    offset += n;
    }
    adata = new AudioData(b2);
    ads = new AudioDataStream(adata);
    AudioPlayer.player.start(ads);
    }

    This is just raw test code, may need some refine. It is using Sun audio package.
    The only problems is there are some pauses at about every 3 - 8 seconds (note that FRAME_LEN is 8000, i.e. 1 second so I don't have gaps between each frame). I need to find a way to improve that. Any suggestions are welcomed of course!

    Adrian

  15. #15
    adrianb is offline Member
    Join Date
    Mar 2011
    Posts
    7
    Rep Power
    0

    Default

    Problem fixed!

    url = new URL("http://192.168.3.8/axis-cgi/audio/receive.cgi?httptype=singlepart");
    is = url.openStream();
    AudioPlayer.player.start(is);

    works just fine! No need for that double buffering scheme, no need for AudioData and AudioDataStream

  16. #16
    cultclassic is offline Member
    Join Date
    Mar 2011
    Posts
    64
    Rep Power
    0

    Default

    Thanks for posting the solution. Good Code Karma.

  17. #17
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Playing mid in java pls help
    By Hees in forum New To Java
    Replies: 5
    Last Post: 06-20-2010, 06:15 AM
  2. Replies: 0
    Last Post: 04-24-2010, 08:27 PM
  3. Re-playing sound
    By JSK in forum CLDC and MIDP
    Replies: 0
    Last Post: 02-06-2008, 11:34 AM
  4. Playing sound in applet??????
    By Bagesh in forum Java Applets
    Replies: 2
    Last Post: 07-13-2007, 04:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •