Event when streaming sound is ready to play

Hello,
I'd like to know, when a streaming sound has preloaded enough
and would
start to play.
Since I have also to preload some images and xml files, I
load a
streaming sound, stop it immediately and when everything has
enough
buffer, I want to start them all manually...
How can I do this?
josp

Hi josp,
I have the same question and I'm wondering--did you ever
figure it out?
Thanks,
mew

Similar Messages

  • Clicking noise when streaming sound to SourceDataLine

    Hello,
    I'm trying to stream sound to the PC's speakers using SourceDataLine, but I have trouble getting rid of a clicking noise.
    It seems to occur when sourceDataLine.available() equals sourceDataLine.getBufferSize(). Is there a way to avoid this?
    I am dealing with an audio of indeterminate length. Here's the test code:
    import javax.sound.sampled.AudioFormat;
    import javax.sound.sampled.AudioSystem;
    import javax.sound.sampled.DataLine;
    import javax.sound.sampled.LineEvent;
    import javax.sound.sampled.LineListener;
    import javax.sound.sampled.LineUnavailableException;
    import javax.sound.sampled.SourceDataLine;
    public class PlaybackLoop implements LineListener {
       SourceDataLine sourceDataLine;
       AudioFormat format;
       public PlaybackLoop() throws LineUnavailableException {
          AudioFormat.Encoding
              encoding = AudioFormat.Encoding.PCM_SIGNED;
          int sampleRate = 8000; // samples per sec
          int sampleSizeInBits = 16; // bits per sample
          int channels = 1;
          int frameSize = 2;  // bytes per frame
          int frameRate = 8000; // frames per sec
          // size of 1 sample * # of channels = size of 1 frame
          boolean bigEndian = true;
          format = new AudioFormat(
                encoding,
                sampleRate,
                sampleSizeInBits,
                channels,
                frameSize,
                frameRate,
                bigEndian);
          // PCM_SIGNED 8000.0 Hz, 16 bit, mono, 2 bytes/frame, big-endian
          DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
          sourceDataLine = (SourceDataLine) AudioSystem.getLine(info);
       public synchronized void play() throws LineUnavailableException,
                                              InterruptedException {
          int bytesPerSec = (int) format.getFrameRate() * format.getFrameSize();
          int intervalMs = 200;
          int loop = 50;
          int bytesSize = bytesPerSec * intervalMs / 1000;
          byte[] bytes = new byte[bytesSize];
          // creates a high pitched sound
          for (int i = 0; i < bytesSize / 2; i++) {
             if (i % 2 == 0) {
                writeFrame(bytes, i, 0x05dc);
             } else {
                writeFrame(bytes, i, 0x059c);
          sourceDataLine.open(format, 16000);
          sourceDataLine.addLineListener(this);
          int bufferSize = sourceDataLine.getBufferSize();
          System.out.println(format.toString());
          System.out.println(bufferSize + " bytes of line buffer.");
          long nextTime = System.currentTimeMillis() + intervalMs;
          sourceDataLine.start();
          for (int i = 0; i < loop; i ++) {
             int available = sourceDataLine.available();
             if (available == bufferSize) {
                // clicking noise occurs here
                System.out.println("*");
             int w = sourceDataLine.write(bytes, 0, bytesSize);
             long currentTime = System.currentTimeMillis();
             if (w != bytesSize) {
                System.out.println("Not all written.");
                // TODO
             // time adjustment , to prevent accumulated delay.
             long delta = (nextTime - currentTime);
             long wait = intervalMs + delta;
             if (0 < wait) {
                this.wait(wait);
                nextTime += intervalMs;
             } else {
                nextTime = currentTime + intervalMs;
          System.out.println();
          System.out.println("End play()");
       public static void main(String[] args) throws LineUnavailableException,
                                                     InterruptedException {
          new PlaybackLoop().play();
       public static void writeFrame(byte[] bytes, int halfwordOffset, int value) {
          writeFrame(bytes, 0, halfwordOffset, value);
       public static void writeFrame(byte[] bytes, int byteOffset,
                                     int halfwordOffset, int value) {
          byteOffset += 2 * halfwordOffset;
          bytes[byteOffset++] = (byte) (value >> 8);
          bytes[byteOffset++] = (byte) (value >> 0);
       public void update(LineEvent event) {
          System.out.println();
          System.out.print("Update:");
          System.out.println(event.getType().toString());
    }

    I have modified the code so that it shows how the audio goes out of synch
    import javax.sound.sampled.AudioFormat;
    import javax.sound.sampled.AudioSystem;
    import javax.sound.sampled.DataLine;
    import javax.sound.sampled.LineEvent;
    import javax.sound.sampled.LineListener;
    import javax.sound.sampled.LineUnavailableException;
    import javax.sound.sampled.SourceDataLine;
    public class PlaybackLoop implements LineListener {
         SourceDataLine sourceDataLine;
         AudioFormat format;
         public PlaybackLoop() throws LineUnavailableException {
              AudioFormat.Encoding
                    encoding = AudioFormat.Encoding.PCM_SIGNED;
              int sampleRate = 8000; // samples per sec
              int sampleSizeInBits = 16; // bits per sample
              int channels = 1;
              int frameSize = 2;  // bytes per frame
              int frameRate = 8000; // frames per sec
              // size of 1 sample * # of channels = size of 1 frame
              boolean bigEndian = true;
              format = new AudioFormat(
                        encoding,
                        sampleRate,
                        sampleSizeInBits,
                        channels,
                        frameSize,
                        frameRate,
                        bigEndian);
              // PCM_SIGNED 8000.0 Hz, 16 bit, mono, 2 bytes/frame, big-endian
              DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
              sourceDataLine = (SourceDataLine) AudioSystem.getLine(info);
         public synchronized void play() throws LineUnavailableException, InterruptedException {
              int bytesPerSec = (int) format.getFrameRate() * format.getFrameSize();
              int intervalMs = 200;
              int loop = 400;
              int bytesSize = bytesPerSec * intervalMs / 1000;
              byte[] bytes = new byte[bytesSize];
              // creates a high pitched sound
              for (int i = 0; i < bytesSize / 2; i++) {
                   if (i % 2 == 0) {
                        writeFrame(bytes, i, 0x05dc);
                   } else {
                        writeFrame(bytes, i, 0x059c);
              sourceDataLine.open(format, 16000);
              sourceDataLine.addLineListener(this);
              int bufferSize = sourceDataLine.getBufferSize();
              System.out.println(format.toString());
              System.out.println(bufferSize + " bytes of line buffer.");
              long nextTime = System.currentTimeMillis() + intervalMs;
              sourceDataLine.start();
              for (int i = 0; i < loop; i ++) {
                   int available = sourceDataLine.available();
                   if (available == bufferSize) {
                        // clicking noise occurs here
                        System.out.println("*");
                   int w = sourceDataLine.write(bytes, 0, bytesSize);
                   if (w != bytesSize) {
                        System.out.println("Not all written.");
                        // TODO
                   // printing time drift
                   if (i % 100 == 0) {
                        long currentTime = System.currentTimeMillis();
                        // this number increases
                        System.out.println(nextTime - currentTime);
                   nextTime += intervalMs;
              System.out.println();
              System.out.println("End play()");
         public static void main(String[] args) throws LineUnavailableException, InterruptedException {
              new PlaybackLoop().play();
         public static void writeFrame(byte[] bytes, int halfwordOffset, int value) {
              writeFrame(bytes, 0, halfwordOffset, value);
         public static void writeFrame(byte[] bytes, int byteOffset,
                                             int halfwordOffset, int value) {
              byteOffset += 2 * halfwordOffset;
              bytes[byteOffset++] = (byte) (value >> 8);
              bytes[byteOffset++] = (byte) (value >> 0);
         public void update(LineEvent event) {
              System.out.println();
              System.out.print("Update:");
              System.out.println(event.getType().toString());
    }The output looks like this:
    PCM_SIGNED 8000.0 Hz, 16 bit, mono, 2 bytes/frame, big-endian
    16000 bytes of line buffer.
    Update:Start
    200
    1200
    1450
    1700
    End play()
    The printed number keeps on rising. (Maybe I'm not sending enough information to the audio input stream?)
    The printed number should be stable if in synch, but it continues to rise, signifying that it's playing audio faster than it's being provided. When the audio input source is from a network streamed audio (instead of the test audio source in this example), it results in a buffer under run, which causes the clicking sound.

  • Delaying a symbol playing until its audio is ready to play

    I'm trying to create an elearning  composition that requires voice over. I created a symbol that has  an audio embedded in its timeline. When the symbol plays the audio also plays.
    Sometimes, however the audio is delayed and falls out of sync with the animation. Is there a way to know when the audio is ready to play like a property of audio 'isPlaying' or the html5 audio event
    'can play' that I can use? I enabled preloading in my audio.

    Hi there,
    Blokeish has given you a very good start, but rather than listening for the canplay event, I'd recommend first stopping your symbol timeline right away, and then listening for the audio element's playing event.
    For instance, you could add this to your compositionReady even:
    // listens for the audio element's playing event, and then plays your symbol
    sym.getSymbol("your_symbol").$("your_audio element")[0].addEventListener("playing",function() {
            sym.getSymbol("your_symbol").play();
    // this now plays your audio element, which triggers your listener, above
    sym.getSymbol("your_symbol").$("your_audio element")[0].play();
    And then add a trigger to your symbol timeline at time zero to stop it:
    sym.stop();
    I'd expect this to delay your symbol playback reliably (especially when audio is preloaded), because your symbol won't play until your audio actually begins playing.
    hth,
    Joe
    EDIT: Also listening for the canplaythrough event should make this pretty rock-solid, especially if you've got a large audio file and you're worried about re-buffering

  • MacBook shuts down when streaming video

    I use safari, so my assumption is the problem lies there. I did a software update in January along with upgrading to snow leopard but this problem has been happening since before then.
    Its only a few years old and the only thig that's wrong with it is the battery is dead and needs replaced but I have my charger plugged in 24/7. would that have anything to do with streaming video?
    Has this ever happened to anyone?

    I've found that the computer only shuts down when streaming netflix. 
    I can play videos on youtube or vimeo long periods of time without the computer crashing.
    When streaming netflix, the computer turns off within 5 minutes or less usually.
    I have the newest version of silverlight installed and older versions deleted from my hd.
    Does this information point to another or more specific problem?
    Have others experienced a similar issue with regard to netflix or silverlight?

  • Flash animation with stream sound not playing in mac

    Dear all,
    I have made a 5 min animation with stream sound. Its playing perfectly in PC. But in mac, its not playing. Stream sound starts from frame 60. So mac plays the swf plays till 60 frame, after that it pauses. I tried importing different sound format (wav, aif, mp3) and tried with all sound export setting but the problem remain same; its playing only till 60. When i removed the sound, it played till end. Even with event sound, it plays till end. But with stream sound, the problem. The problem is only in mac; in pc its perfect.
    I am using VMware Mac OS x leopard in window xp for testing purpose. I tested it in laptop with mac; but the problem is same. What could be the solution?
    Thanks in advance. Waiting for solution.
    Bhushan Pradhan
    spherenepal.com

    Dear all, I solved the problem myself. The problem was with the sound driver of mac. After installing sound driver, the problem is gone. Bhushan

  • How do i get itunes or any other program for ipod to play one song and then stop instead of contiuing playing. I need it to be in the same playlist and ready to play the next song when I press play?

    how do i get itunes or any other program for ipod to play one song and then stop instead of contiuing playing. I need it to be in the same playlist and ready to play the next song when I press play?

    Good luck.  I tried to do this to cue sound effects for a theater, and never found anything.  iTunes will definitely *not* do this, nor was I able to find any player that would play one song at a time in a single playlist. 
    In my case, I ended up using AutoHotkey to tie individual tracks to the keys on an external keypad. This was an excellent solution for my problem, but I don't think AHK runs on Macs.
    One workaround is to make a folder, and fill it with *shortcuts* to the songs you want (ie, the actual files).  You can change the names to start with numbers to get them in the right order.  Then if you double-click on one it will play just that song.  You'll still have to double-click on each song.
    Might be a good time to learn AppleScript   It would  also be pretty easy to write a Java app to do this.

  • NetStream.Play.InsufficientBW when streaming server side playlist

    Hi
    I am streaming pre recorded audio files (mp4) to an AIR client. I have tried two different solutions,
    streaming the file directly with the NetStream.play("mp4:xxxxx.m4a") and creating a server side playlist, adding the
    same sound clip and then streaming the playlist. The problem is, when streaming the playlist i get a few NetStream.Play.InsufficientBW, this does not happen when streaming the file direct. Both solutions uses bufferTime=1.0
    I would like to use a server side playlist to implement a simple key solution so that the client dont know the full path to
    the file, but instead sends a key to a custom server side function that looks up the file path and creates a stream for the client.
    TIA
    Ruben Chadien
    FMS 4.0(linux)

    Subscribing via playlist and playing file directly are two different things , as first one is live mode of play while other is playing recorded file - so the way streams are delivered are also quite different. Can you try setting higher buffer and see if that helps or if you don't want to set higher buffer, see if disabling AggregateMessages (you will find the tag in Application.xml under Live/Queue) helps

  • Stop sound when another sound plays

    Hey guys,
    Using Flash Pro CC 2014, Actionscript 3
    I am working on a soundboard and use buttons that play sounds, and I want to make it that when a new sound plays, it automatically stops the current sound from playing, that way 2 sounds dont play at same time.
    But I also have a button that stops all sounds, I am using the "Click to Stop All Sounds" code under Audio and Video in the Code Snippets.
    So I am basically wanting to make sure I can do both, keep the stop all sounds button, but also have it when you press any sound button, it stops all sounds and starts playing the current button/sound. Any suggestions?
    BTW I am setting up symbols as buttons, not movie clips incase you need to know for coding, but I can switch to movie clips if its easier. I was just used to buttons on older versions of Flash for simple stuff like this.
    Thanks.

    Thanks for the reply, I am new to actionscript 3 but am a fast learner. Maybe I am doing this wrong, but when I add the code it simply stops the sounds, but it wont play the sound from the button that I just clicked on. I want it to play the sound button clicked on, and also stop any other sounds that are currently playing.
    For Flash 8, as2, I would add this to the button:
    on (press)
        stopAllSounds ();
    On as3, does it need to say this?
    button_2.addEventListener(MouseEvent.CLICK, fl_ClickToStopAllSounds);
    function fl_ClickToStopAllSounds(event:MouseEvent):void
        SoundMixer.stopAll();
    thanks for your help

  • When streaming a movie with the new Apple TV, and using a DSL Internet connection, all audio sound works, e.g., the music track, but the audio track with the actor's voices, does not work. What can I do?

    When streaming a movie with the new Apple TV, and using a DSL Internet connection, all audio sound works, e.g., the music track, but the audio track with the actor's voices, does not work. What can I do?

    Hi Brian,
    Thanks restoring and restarting didn't fix my problem - i have started it fresh and still it doesn't work. Basically I press ONCE on the remote, after the machine has not had any commands for 10 minutes, and the cursor skips from one end of the menu to the other - so I can't choose network or update software etc - I sometimes manage to stop it randomly in the middle of the menu if I press on a command in the middle of the cursor skipping all the menu steps...not sure what the problem is but I have basically not used my brand new apple tv since I bought it for that reason! I should call Apple support I suppose! grrrr hate wasting time with stuff like this!
    Thanks for your help though!
    Pernille

  • I placed my ipad on top of my CPU with a music playing,i heard a crack on the sound and when i checked it,i can no longer hear a sound playing on my ipad.i tried to check place a headphone its still playing a sound but when i pull it out,wont play at all.

    i placed my ipad on top of my CPU with a music playing,i heard a crack on the sound and when i checked it,i can no longer hear a sound playing on my ipad.i tried to check place a headphone its still playing a sound but when i pull it out,wont play at all.

    I don't know if this will work but it's worth a try. I wonder if somehow you ended up with a short inside of your iPad. Give the things below are trying to see if that helps. Good luck.
    Try a Restart. 
    Press and hold the Sleep/Wake button for a few seconds until the red "slide to power off" slider appears, and then slide the slider. Press and hold the Sleep/Wake button until the Apple logo appears.
     Resetting your settings
    You can also try resetting all settings. Settings>General>Reset>Reset All Settings. You will have to enter all of your device settings again.... All of the settings in the settings app will have to be re-entered. You won't lose any data, but it takes time to enter all of the settings again.
    Resetting your device
    Press and hold the Sleep/Wake button and the Home button together for at least ten seconds, until the Apple logo appears. Apple recommends this only if you are unable to restart it.
    Or if this doesn't work and nobody else on the blog doesn't have a better idea you can contact Apple. 
    Here is a link to their contacts with most of the information below. 
    http://www.apple.com/contact/

  • I bought my Iphone 5 a week ago, now suddenly my sound is gone when i play games, i checked everything and the weird thing is that when i put my headphone in i CAN hear the sound when in games, also he just plays music whitout my headphone. What could it

    Hello so as you can see in my question i have troubles with my sound
    I cant hear annything of my sound in game and i did check everything
    The weird thing is that when i put my headphone in i do hear the sound
    Also my music plays without my headphone
    Wat can it be ? Pls help !

    Ok, a little clarification then, you can hear music fine with the speaker and headphone?  You can hear a game's music fine with the headphone but not with the speaker?  Do you get the notification sounds ok with the speaker?
    If the speaker sound is acceptable with everything except the game then there is a problem with that game and its settings.
    If that is the case, you might want to try deleting the game and then downloading and reinstalling the game to see if that helps the problem.

  • I bought a movie on iTunes but when I try to watch it plays back slowly with no sound.  Then the video will speed up and the sound will work for a moment then off again and back to slow motion.  I have a dell laptop running windows 7

    The description says it all.    I bought a movie on iTunes but when I try to watch it plays back slowly with no sound.  Then the video will speed up and the sound will work for a moment then off again and back to slow motion.  I have a dell laptop running windows 7

    Hi Normanwh,
    If you are having video playback issues in iTunes on your Windows machine, you may find the following article helpful:
    Apple Support: Troubleshooting iTunes for Windows Vista or Windows 7 video playback performance issues
    http://support.apple.com/kb/ts1718
    Regards,
    - Brenden

  • StopAllSounds vs. new Streaming Sound not playing

    In my timeline, I'm using a stopAllSounds action (because the
    user could be coming from anywhere in the movie and I need to stop
    whatever narration might be playing), then, in the next frame, I'm
    trying to stream a new sound. My problem is that the streaming
    sound doesn't play. I've tried adding a few frames between the
    stopAll Sounds action and the start of the streaming sound, but
    that doesn't seem to be the problem. Any ideas would be greatly
    appreciated.
    - BillG

    I was about to try your suggestion, but after sending a few more test emails, I discovered that it does in fact play the sound sometimes.  I sent about 20 test emails, and they were all received using the "idle" command, with about 75% of them playing the sound.  There was a 5-10 second delay between the messages being received and the sound playing that I don't remember from Snow Leopard, but I'm not positive about that.
    It shouldn't be the actual sound that is the issue, being that it is played sometimes, but I still don't know why it's not playing every time.  I tried receiving messages with the app running in the background, with it minimized, and with it as the active window, but I couldn't find any specific instance that caused it to not play the sound.
    I wasn't having this issue in Mail 4.  It didn't start until I installed Lion, which I did a clean install of, if it matters.
    I'm still open to thoughts on this, and thank you for your help.

  • I just rented a movie and waited 2 1/2 hrs for it to download, which is fine, but when I paused it to run to the kitchen and came back and resumed...it said "Ready to play in 5 hours and 16 minutes. What in the world!? My 24 hrs will be up b4 I can watch

    I just rented a movie on my Apple TV and waited 2 1/2 hrs for it to download, which is fine, but when I paused it to run to the kitchen and came back and resumed...it said "Ready to play in 5 hours and 16 minutes. What in the world!? My 24 hrs will be up b4 I can watch

    You must have a slower connection if it took 2.5 hours, did you pause it or exit out to the main screen? I've paused movies many times and it resumes..it could be due to the connection as well  so what is your actual speed? Check www.speedtest.net Wifi or ethernet? Have you changed the DNS settings?

  • Just upgraded to 6.1 and immediately lost Dolby Digital 5.1 sound when streaming Netflix. Anyone else experience this? Any fix? Thanks!

    Just upgraded to 6.1 and immediately lost Dolby Digital 5.1 sound when streaming Netflix. Anyone else experience this? Any fix? Thanks!

    You're not the only one. I'm having the same problem, currently no solution is known.
    See this thread: https://discussions.apple.com/thread/6012766

Maybe you are looking for