Play Streaming Audio

I'm busy designing an app to play audio from a link. The audio is being streamed by a Shoutcast server. The link I have been given is 'http://live.rmr.ru.ac.za'. I've got the following code so far:
    // Read sampled audio data from the specified URL and play it
    private void streamSampledAudio(URL url)
        throws IOException, UnsupportedAudioFileException,
               LineUnavailableException
        ain = null;  // We read audio data from here
        SourceDataLine line = null;   // And write it here.
        try {
            // Get an audio input stream from the URL
            ain=AudioSystem.getAudioInputStream(url);
            // Get information about the format of the stream
            AudioFormat format = ain.getFormat( );
            DataLine.Info info=new DataLine.Info(SourceDataLine.class,format);
            // If the format is not supported directly (i.e. if it is not PCM
            // encoded), then try to transcode it to PCM.
            if (!AudioSystem.isLineSupported(info)) {
                // This is the PCM format we want to transcode to.
                // The parameters here are audio format details that you
                // shouldn't need to understand for casual use.
                AudioFormat pcm =
                    new AudioFormat(format.getSampleRate( ), 16,
                                    format.getChannels( ), true, false);
                // Get a wrapper stream around the input stream that does the
                // transcoding for us.
                ain = AudioSystem.getAudioInputStream(pcm, ain);
                // Update the format and info variables for the transcoded data
                format = ain.getFormat( );
                info = new DataLine.Info(SourceDataLine.class, format);
            // Open the line through which we'll play the streaming audio.
            line = (SourceDataLine) AudioSystem.getLine(info);
            line.open(format); 
            // Allocate a buffer for reading from the input stream and writing
            // to the line.  Make it large enough to hold 4k audio frames.
            // Note that the SourceDataLine also has its own internal buffer.
            int framesize = format.getFrameSize( );
            byte[] buffer = new byte[4 * 1024 * framesize]; // the buffer
            int numbytes = 0;                               // how many bytes
            // We haven't started the line yet.
            boolean started = false;
            for(;;) {  // We'll exit the loop when we reach the end of stream
                // First, read some bytes from the input stream.
                int bytesread=ain.read(buffer,numbytes,buffer.length-numbytes);
                // If there were no more bytes to read, we're done.
                if (bytesread == -1) break;
                numbytes += bytesread;
                // Now that we've got some audio data to write to the line,
                // start the line, so it will play that data as we write it.
                if (!started) {
                    line.start( );
                    started = true;
                // We must write bytes to the line in an integer multiple of
                // the framesize.  So figure out how many bytes we'll write.
                int bytestowrite = (numbytes/framesize)*framesize;
                // Now write the bytes. The line will buffer them and play
                // them. This call will block until all bytes are written.
                line.write(buffer, 0, bytestowrite);
                // If we didn't have an integer multiple of the frame size,
                // then copy the remaining bytes to the start of the buffer.
                int remaining = numbytes - bytestowrite;
                if (remaining == 0)
                    System.arraycopy(buffer,bytestowrite,buffer,0,remaining);
                numbytes = remaining;
            // Now block until all buffered sound finishes playing.
            line.drain( );
        finally { // Always relinquish the resources we use
            if (line != null) line.close( );
            if (ain != null) ain.close( );
    }Although I get an UnsupportedAudioFileException when using the link above.
Please can someone point me in the right direction on how to play streaming audio?

Please can I refer you to this thread.
I'm struggling like you can't believe to do something which I thought would be quite simple.

Similar Messages

  • Droid Razr Bug.  Won't play streaming audio from websites.

    My Droid Razr won't play streamed audio from a website and won't play .wav files attached to e-mails.  That's annoying.  
    Motorola tech support said problem will be fixed upon next upgrade of Android OS.  
    My phone is currently running Android OS 2.3.5.  
    Does anyone now of a quicker fix?
    Does anyone know when an OS upgrade will be available for the Droid Razr?
    Thx!

    i got the same issue on my ipod. i figured the whole idea of converting the format would solve the issue. never really found out how to solve it. i'll be watching this post to see if anyone has a solve for this issue.

  • HT204387 Can we play streaming audio from one device to other  device using A2DP profile ?

    Hi,
    Can we play streaming audio over two paired device .Please provide help us.
    Thanks
    Santosh

    If the other end supports the following
    http://support.apple.com/kb/HT3647
    you can plug an A2DP receiver into any speakers etc via the aux input
    and play music  from an iPod/iPad/iPhone

  • Bug: OS 4.5 Media Player does not allow BB screen to shut off when playing streaming audio

    I updated my Verizon Pearl 8130 to OS 4.5.  Now, when streaming audio from a station such as "Groove Salad" at http://www.somafm.com, the screen does not shut off but stays on indefinitely, wasting precious battery power.  OS 4.3 Media Player did allow the screen to turn off when streaming audio.
    - Bill

    I have a similar issue since upgrading to to 4.5 with my vzw 8130.   with 4.3 I was able to stream audio and then have it run in the background to read messages or address book for example all the while the audio was still playing.   Now once I get the audio streaming and back out to the main menu the media player quits.

  • Want to play streaming audio (*.rm), Mobile Safari won't.

    World's most boring use: listening to archived streaming audio of Maryland legislators. They use RealAudio.
    Tried Safari, won't play it (it downloads the *.ram file to DropBox).
    If  iTunes plays them I have no idea how to specify that.
    They also use Silverlight video streaming, which as I understand it is not something you can see on an iPad.

    http://mlis.state.md.us/2012RS/hearsch/committee-hearings-index.htm --
    gives you Senate or House choices. Here's the Senate page:
    http://mlis.state.md.us/mgaweb/senatecmtaudio.aspx

  • Playing streaming audio using Airport

    I have a iMac4 (10.4.11) with an AirPort Extreme (0x14E4, 0x89). I also have an Airport "box", plugged in to the wall, and connected to the back of my stereo. iTunes plays without a hitch through the stereo, but baseball season is coming and I am trying to figure out how to stream audio (not coming through iTunes) via Airport to my stereo. Hope that's not too convoluted!
    Can this be done? Must I resort to fuzzy AM signals?

    This can be done with a low cost utility called Airfoil - see:
    http://www.rogueamoeba.com/airfoil/mac/

  • Latest release won't play streaming audio

    An interface that many radio stations use for streaming no longer loads in Firefox. IE will play it for me. It finds the station but when the notice "loading media" appears, it never connects and starts the audio in Firefox. Representative link is given below.
    Here's one URL example:
    http://www.999litefm.com/mediaplayer/?station=WLQT-FM&action=listenlive&channel_title=

    You can try to install the new WMP plugin.
    See http://kb.mozillazine.org/Windows_Media_Player#Missing_plugin

  • Firefox V 25.0.1 on an iMac OSX 10.9 will not play streamed audio from a web site. Audio on Safari V7 OK. Any ideas on how to get the Firefox audio to play?

    The audio on the site is in MP3 format. The site is coded in PHP.

    I'm not sure if the current Firefox release is supporting MP3 in an audio or video tag if that is what is used to play this media file.
    *[https://bugzilla.mozilla.org/show_bug.cgi?id=851290 bug 851290] - Use GStreamer on Mac for H.264/MP3/AAC playback (instead of AV Foundation)
    <i>Please do not comment in bug reports: https://bugzilla.mozilla.org/page.cgi?id=etiquette.html</i>

  • Play streaming audio from Shoutcast

    Hello,
    I am new to Flex.  I am trying to create a simple desktop app to play a live radio stream from a shoutcast server.  I cannot get it to play.  I am now wondering if it is even possible using the Flex/Air platform.  Here is my code:
    package
    import flash.display.Sprite; 
    import flash.display.StageAlign; 
    import flash.display.StageScaleMode; 
    import org.osmf.elements.AudioElement; 
    import org.osmf.media.MediaPlayerSprite; 
    import org.osmf.net.StreamType; 
    import org.osmf.net.StreamingURLResource; 
    public class StreamingURLResourceExample extends Sprite{
    public function StreamingURLResourceExample(){
    super(); 
    stage.scaleMode = StageScaleMode.NO_SCALE;
    stage.align = StageAlign.TOP_LEFT;
    var mediaPlayerSprite:MediaPlayerSprite = new MediaPlayerSprite(); 
    var audioElement:AudioElement = new AudioElement(); 
    audioElement.resource =
    new StreamingURLResource("http://38.96.148.91:4152", StreamType.LIVE); 
    addChild(mediaPlayerSprite);
    mediaPlayerSprite.media = audioElement;

    In a nutshell reflectors are redirects. Basically, what you see as requests are temporary dummy things and stream is actually coming from different address. Sometimes reflectors are xml files. This is one of the ways companies protect their assets from hacking.
    I cannot find anything on shoutcast that allows access by third party player. I suspect it may not be possible. At least with Flash. Even if you can access currently invoked stream, next time you attempt it - it may fail. Try to stream video from YouTube - you can right after you got the address but after that server is switched and you cannot stream it any longer.

  • [Bug] Playing stream audio from the editor almost always starts from beginning.

    Whenever I am creating a movie clip with an audio layer set to "stream" I usually click certain points of the movie and hit enter to see and hear it. In Flash CC however, it seems about 95% of the time no matter what frame I am on when I hit enter the audio starts from the beginning and is not in sync. There have been a few cases in which the audio started at right frame but I haven't yet been able to isolate the process. Audio works great in the exported SWF, this issue is just just with the editor.

    This bug still hasn't been fixed. I don't recommend Flash for any animator; the issue makes syncing to music and vocals extremely frustrating. This bug has been around for months without solution.
    Running as administrator does not solve the problem.
    You will have the audio bug even if you do not have a Beats Audio Soundcard.
    The longer and more complicated your project, the more frequently the bug happens. When it first begins (around 15-30 seconds worth of frames and about 7 layers) you can make the audio stream as it should by clicking your audio track, setting it to "stop," saving your project, and setting the audio to "stream" again.
    However, when you have about 60 seconds on your timeline, the bug happens a lot more, and you have to actually close the project to get the sound to work again if you do not have the patience to wait for it to fix itself. The wait ranges from 30 seconds to several minutes to never fixed until you close. It's highly unpredicatable. Sometimes it is not enough to close the project, in which case you must quit Flash and start it up again.
    It happens with both mp3 and wav sounds.
    After a month of this bug, I still can't pinpoint what causes it. It's completely random.
    This post suggests it has something to do with scrubbing the timeline. I haven't been able to replicate the bug by doing this. It happens whether or not you use the slider or just click on frames to navigate.
    My system specs:
    Windows 7 Home Premium (Service Pack 1)
    64-bit operating system
    Processor: Intel i5-4670K CPU @3.40 GHz
    RAM: 8 GB
    NVIDIA GeForce GTX 660 Graphics Card
    Audio is also NVIDIA High Definition Audio
    The bug happens even if I plug in headphones to a regular audio port not on the graphics card.
    Other audio types I have are the Intel Display Audio and Realtek High Definition Audio. I've tried messing with audio settings to no avail.

  • Pearl won't play streaming audio

    I installed Slacker Mobile radio, and also the app for XM radio, and I couldn't get either one to play the streaming content. How can I fix this?

    You can try to install the new WMP plugin.
    See http://kb.mozillazine.org/Windows_Media_Player#Missing_plugin

  • Palm Pre - Here is how to create a web bookmark to launch a streaming audio site

    Once you have a URL that you have confirmed as working with the Pre to play streaming audio, unfortunately you can't create a bookmark when playing the streaming audio.  Here is a way you can create a bookmark to easily launch the site again to play the streaming audio:
    My example is for WHYY the PBS station in Philadelphia.  
    You can either create a new bookmark or use an existing one you don't use.  If you create a new bookmark you can set an icon you want to use.
    Use this process if you are creating a new bookmark.
    1a.    I entered the URL for WHYY, http://www.whyy.org, so I could create an icon with the visual for WHYY.  This step is not necessary and doesn't need to be related to the streaming audio content, it just allowed me to get the icon I wanted.
    1b.  With the WHYY site loaded I choose Menu>Add Bookmark
    1c.  I touched on the icon at the top of the window and adjusted the boundaries to just include the WHYY logo
    2.  I then touched in the URL line and changed the URL to http://207.245.67.204/listen.pls
    3.  I then touched the "Add Bookmark" button
    Use this process if you are using an existing bookmark that you want to recycle.  This bookmark will not be usable in its old form again.
    1a.  Within a web card tap Menu>Bookmarks to display the existing bookmarks.
    1b.  Find the bookmark you want to use and tap the information button, "i", at the right
    2.  Then tap in the URL line and change the URL to http://207.245.67.204/listen.pls
    3.  Then touch the "Add Bookmark" button 
    That's it.  You can now choose "Web" from the Launcher and touch the new bookmark and the streaming audio will launch. 
    Post relates to: Pre p100eww (Sprint)
    Post relates to: Pre p100eww (Sprint)
    Post relates to: Pre p100eww (Sprint)

    I had the same problem and found this article very useful.  It's clear, concise, and thorough.  I wish all step-by-step how-to documents were that readable!
    Thank you for posting,

  • Streaming Audio Application Problem

    HI All,
    I have written a small application for streaming audio in flash cs3/as2. One strange thing I observed that I cant play streaming audio from
    all the free streaming website I add to the list. After the website address if I mention the port number then cant get the audio.
    I tried with this address  http://stream.radiosai.net:8002 that is added to trusted list/path. My analyse is that if the address has strings like ":8002" i.e port number then flash doesn't allow them to use... I also observed that if I run the swf file using internet explorer then everything works fine... however test movie (Ctrl+ENTER) from CS3 tool doesn't work   Please help me....
    Message was edited by: Manjunath Hegde

    Here's the code.
    EDIT
    As always seems to happen for me, as I posted my code, I
    found what was wrong with it. In my playSong function, I was saying
    s = new Sound(); without reasigning the handler for the event. I
    just didn't see it until right after I posted my code.
    Thanks for your help anyway.

  • Streaming audio stops on Satellite P205D-S7438

    Everytime I try to play streaming audio, it comes on and plays fine from the embedded Windows media player, but stops at 20 seconds.  It doesn't matter if it is streaming live or if the file has been archived.  If I try to play it from the external player option, the player opens but nothing happens...won't even play the 20 seconds.  I am running Vista Home Premium.  I have checked some other forums and have reset the internet connections options and have it set to auto proxy under the internet connection settings.  Any suggestions?  I did see where someone else with the same computer had had the same problem, so I wondered if it was related to something on this particular computer model??  Any help would be appreciated.
    Just so you know, the website I've been trying to access the streaming audio from is at
    http://www.nhsbn.com/broadcasts/index.cfm?fuseaction=affilbrd&broadcasterid=154&Org=nhsbn&CFID=94522...
    I don't think that makes any difference though...I've had the same problem trying to stream video from a college sports site.  Also, the above link works fine for a different model of Toshiba Satellite in the house. 

    ADDED information:You might not have a correct version of Windows Media Player installed. Microsoft's Media Player is Version 11.  Depending on which version of Windows you are running, you should make sure you upgrade to Version 11, at the very least to utilize.
    You can determine your Windows Media Player version by starting the player from the Windows "Start" button, and then clicking Windows Media Player from the program listing.  Then click "Help" and "About" from the menu.
    With Windows Media Player, occasionally the player does not automatically download the necessary codecs for the broadcast. In order to fix this, you must set Windows Media Player to " automatically download codecs".
    Open the Windows Media Player from the start menu.  Click "Tools/Options/Player", and make sure that the box, "Download Codecs Automatically", is checked. Restart Windows Media Player, and attempt to open the broadcast again.

  • Safari not playing streaming video

    Hi,
    For some reason safari 4.3 is not playing streaming video such as that shown on CNN. Also, my Macbook is not playing streaming audio. If any of you folks can help with an answer I'd appreciate the help. I am using 10.61 on both machines.
    Thanks
    Jack

    http://flip4mac.com
    Look for the "beta" version for Snow Leopard.

Maybe you are looking for