I’m frustrated

about SoundManag​er2 Buffering Confirmati​on

Hi,

I'm trying to use soundManager2 in a website i'n working on conatining hearing excercises. in one of the excersies I need to play a sequence of sounds in a very specific timing. so I'm using the setTimeout to send the SM2 play command. it works great locally but on the internet there's a problem. since the files take some time to load over the internet, each starts playing at the setTimeout time + it's own random time of loading. so timing is impossible!
tried using 3 events onload, onready and onbufferchange, but non seemed to relate to buffer readiness, only flash element loaded but not the actual file ready in clients machine.

is there any possible way to get confirmation from the soundelement that it's buffer is ready, before I give the timing commands?

help!
Thanks a lot!

Elad
1 person has
this problem
+1
Reply
  • Scott (Official Rep) October 07, 2011 01:07
    Audio is almost always going to have some sort of latency, delay or lag across systems; however, there are a few things you can do to help minimize it. Generally, my findings have been that Windows Vista and 7 machines have more lag than WinXP, and OS X has quite low audio latency.

    It sounds like in your case, you probably just need to ensure the sounds have been fully preloaded before playback begins.

    If you want to play sounds simultaneously, make the play() calls at the same time. If you want to ensure the sounds begin ASAP, make sure you preload them up-front so no buffering is required.

    The simplest way to preload is by specifying autoLoad: true when creating the sounds. If you want to make sure they have loaded before playing, you can assign an onload handler or check the sound's readyState property before allowing the sounds to play.

    For the flash case, set the following which may help to minimize "lag":
    soundManager.flashVersion = 9;
    soundManager.useHighPerformance = true;
    soundManager.useFastPolling = true;

    You might find this preloading example to be of use. You can tell when the sounds have all loaded using the example, and can show a loading screen or prevent the user from starting things until they're all ready to play etc.

    setTimeout() can be a little tricky and does not guarantee accuracy at all, so you will have to keep that in mind.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. indifferent, undecided, unconcerned happy, confident, thankful, excited kidding, amused, unsure, silly sad, anxious, confused, frustrated

  • I’m thankful
    Scott thanks a lot!

    The readyState is what I was looking for, and I'll be able to make it with it.

    However i'm still experiencing one problem:
    The onload event (and also the onready), apparently doesn't trigger when the sounds are ready or loaded at all. I know this because i've created a function that will fire only when all onready events are triggered, and then i'm alerting the readyState and some of the sounds still return 1(meaning: loading...).

    I can solve this creating a while function that will sample the readyState, but I will be much happier using the soundmanager event. Do you know why these events doesn't trigger the right time?

    you can find the whole code and example of the page with the alerts here:
    http://earpiano.freehostingcloud.com/...
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. indifferent, undecided, unconcerned happy, confident, thankful, excited kidding, amused, unsure, silly sad, anxious, confused, frustrated

  • This reply was removed on 2011-10-08.
    see the change log
  • and here's the relevant part of the code

     
    function loadSeq(seqNotes){

    for (i=0; i<seqNotes.length;i++){
    note = seqNotes[i][0];
    seqNotes[i][2] = soundManager.createSound({
    id: note,
    url: 'aud/' + note + audFileExt,
    autoLoad: true,
    onload:waitAndPlay()
    });
    }
    }

    function waitAndPlay(e){

    readynessCount++;
    if (readynessCount==seqNotesAmount){setTimeout("playSeq()",10)}

    }

    function playSeq(){

    for (var i=0; i<seqNotesAmount; i++){
    alert(seqNotes[i][2].readyState)}

    for (var i=0; i<seqNotesAmount; i++){
    note = seqNotes[i][0];
    setTimeout("soundManager.play('" + note + "');",timeBetNotes*i)
    }

    }
    • Scott (Official Rep) October 08, 2011 16:09
      You're close, but note that your assignment of onload is not quite correct.
      onload:waitAndPlay() // = calls waitAndPlay() immediately, and assigns the result of that function to onload.
      What you want is to assign a reference to the function which will then be called later.
      onload: waitAndPlay // later, onload() is called and it then is the same as waitAndPlay()
      I think that change will get things more or less working the way you'd like.
    • This comment was removed on 2011-10-09.
      see the change log
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. indifferent, undecided, unconcerned happy, confident, thankful, excited kidding, amused, unsure, silly sad, anxious, confused, frustrated

  • I’m excited
    Hey! it does. Thank you so much! You really helped me a lot.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. indifferent, undecided, unconcerned happy, confident, thankful, excited kidding, amused, unsure, silly sad, anxious, confused, frustrated