A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 36

Thread: onSoundComplete, attach and play next sound DELAY

  1. #1
    Amiga freak Ironclaw's Avatar
    Join Date
    Jan 2001
    Location
    Sweden
    Posts
    1,650

    onSoundComplete, attach and play next sound DELAY

    It's like this. I have splitted a 1 min song into 8 parts. I attach part 1 by using this code:

    code:
    			s = new Sound();
    s.attachSound("1");
    s.start(0.0, 0);
    s.onSoundComplete = function() {
    gotoAndStop(2)



    When that part is done playing, it goes to frame 2 where the next part is played:

    code:
    			s = new Sound();
    s.attachSound("2");
    s.start(0.0, 0);
    s.onSoundComplete = function() {
    gotoAndStop(3)



    And then goes to frame 3 to play the next part etc...

    The problem is that there is a split second delay between each sound, so it doesnt sound right. Is there a way to fix this?. I thought that the delay is maybe caused cuz it has to stop the sound, goto the next frame and play the next part. So I tried this instead by thinking maybe it's faster:

    code:
    onClipEvent (enterFrame) {
    if (_root.play == "yes") {
    _root.play = "no";
    s = new Sound();
    s.attachSound("0");
    s.start(0.0, 0);
    s.onSoundComplete = function() {
    s = new Sound();
    s.attachSound("1");
    s.start(0.0, 0);
    s.onSoundComplete = function() {
    s = new Sound();
    s.attachSound("2");
    s.start(0.0, 0);
    s.onSoundComplete = function() {
    s = new Sound();
    s.attachSound("3");
    s.start(0.0, 0);
    s.onSoundComplete = function() {
    s = new Sound();
    s.attachSound("4");
    s.start(0.0, 0);
    s.onSoundComplete = function() {
    s = new Sound();
    s.attachSound("4");
    s.start(0.0, 0);
    s.onSoundComplete = function() {
    s = new Sound();
    s.attachSound("5");
    s.start(0.0, 0);
    s.onSoundComplete = function() {
    s = new Sound();
    s.attachSound("6");
    s.start(0.0, 0);
    s.onSoundComplete = function() {
    s = new Sound();
    s.attachSound("7");
    s.start(0.0, 0);
    s.onSoundComplete = function() {
    s = new Sound();
    s.attachSound("8");
    s.start(0.0, 0);
    s.onSoundComplete = function() {
    };
    };
    };
    };
    };
    };
    };
    };
    };
    };
    }
    }



    But this method had the same delay. Maybe it's possible somehow to start the next part 0.5 secs before the previous part has finished playing?... donno how, maybe you guys do?


    Thanks for any help.


    Edit:

    I searched for help again and found this:

    code:
    // create sound object for first loop
    myLoop = new Sound(target to mc);
    myLoop.attachSound("linkage id");

    // create sound object for 2nd loop
    myLoop2 = new Sound(target to another mc);
    myLoop2.attachSound("another linkage id");

    // start first loop
    myLoop.start(0,10);

    // start 2nd loop after first complete
    myLoop.onSoundComplete = function(){ myLoop2.start(0,10)}



    It gives the same delay... and there is nothing wrong with my sound files cuz they are perfect, and if I import them into an audio program and put each part after each other, it plays perfectly.

    edit2:

    Seems like more people has the same problem, and in case you ask, here is some info:

    Each sound loops perfectly using "start(0,99)"
    I am using Windows XP Pro and have tested it inside Flash and with the flash player. Also tried in IE 6.02.
    The Flashplayer is the latest 7.0 and I'm using Flash MX.
    Last edited by Ironclaw; 11-03-2004 at 07:35 AM.

  2. #2
    Registered User
    Join Date
    Apr 2001
    Location
    Akron OH, USA
    Posts
    4,841
    are you importing WAV or mp3?

  3. #3
    Amiga freak Ironclaw's Avatar
    Join Date
    Jan 2001
    Location
    Sweden
    Posts
    1,650
    I know all about sound formats and how wav is loosing some data when converted to mp3... so I always use wav files.

  4. #4
    Registered User
    Join Date
    Apr 2001
    Location
    Akron OH, USA
    Posts
    4,841
    Unfotunately, I dont think there is any thing else you can try to eliminate the gap caused by onSoundComplete.

  5. #5
    Amiga freak Ironclaw's Avatar
    Join Date
    Jan 2001
    Location
    Sweden
    Posts
    1,650
    Ok, so nomatter what, there is no way to remove the gap.. too bad.


    I'm not good at coding, so someone might be able to code this:

    Couldnt a timer eliminate it? Like, if each part is 10 secs, a timer plays the part for 10 secs, then plays next, and next.... without using onSoundComplete. Instead YOU decide when it should jump to the next one. That way I think you could start the next one without a gap... maybe.. but I cant code it so

  6. #6
    Senior Member
    Join Date
    Jan 2003
    Location
    United States
    Posts
    892
    Hi,

    My understanding is that when it comes to mp3 files there is a very, very slight empty space placed before and after the actual sound/music.

    One solution to consider is to try editing the mp3 in a sound editor and see if you can remove the silent spaces. It might be easier than trying to use Action Script.

    Blessings

    jwr
    When all is said and done -- "You MUST be Born Again!" John 3:3

  7. #7
    Amiga freak Ironclaw's Avatar
    Join Date
    Jan 2001
    Location
    Sweden
    Posts
    1,650
    I don't use mp3 cuz I know of that gap, I always use wav.. and my wav files do not have silenced gaps.. they are perfect. It's just that flash is too slow to jump and play the next part so a gap appears.

  8. #8
    Registered User
    Join Date
    Apr 2001
    Location
    Akron OH, USA
    Posts
    4,841
    flash seems to have some built in latency before starting a sound. So it is not technically the onSoundComplete event that is the problem, but probably some processing delay caused after calling the start method.

  9. #9
    Amiga freak Ironclaw's Avatar
    Join Date
    Jan 2001
    Location
    Sweden
    Posts
    1,650
    Yep, something like that. Damn Flash

    I tried using getTimer, setting it to 7300 as the parts is that long. After it has passed 7300, it plays the next part. This worked without delay, but causes delay on different systems.

    Also, using 7300 when playing it through IE, there were no delay. But when playing it with the Flash Player, there was a delay.

    So... When playing it through IE, I had to set it to 7300 for it to loop perfectly. When playing it through the Flash Player, I had to set it to 7800 to make it loop perfectly. But I fear even if it loops perfectly for me in IE with 7300, it wouldn't for you.

    Anyway, attached an example of the onSoundComplete and start(0.0, 99) so that everyone hears the difference.

    Fla
    Swf
    Html

    So many people having the same problem... but the dude who made this:

    Punk-O-Matic

    must know something... cuz the sound in that swf doesnt have any delays. I will mail him and see if he might share the secret.
    Last edited by Ironclaw; 11-04-2004 at 09:57 AM.

  10. #10
    Amiga freak Ironclaw's Avatar
    Join Date
    Jan 2001
    Location
    Sweden
    Posts
    1,650
    He said he doesnt have time for this. So... he didnt want to tell.

  11. #11
    Registered User
    Join Date
    Apr 2001
    Location
    Akron OH, USA
    Posts
    4,841
    can you explain what you are trying to do?

    Perhaps there is another approach that will create the effect you want.

  12. #12
    Amiga freak Ironclaw's Avatar
    Join Date
    Jan 2001
    Location
    Sweden
    Posts
    1,650
    Huh? I have been explaining what I want to do all the time, from my first post. You didn't understand?

    I have splitted a 1 min song into 5 pieces. I want to rebuild that song in Flash by just playing up the next part when the previous is done playing. The best way to do this is to use the onSoundComplete as it checks to see when piece 1 is completed and then plays piece 2. The thing is that there is a delay (silent gap)between each piece. I have tried to fix this, but can't so far.

    So it seems like onSoundComplete has a difficulty in jumping to the next piece as it creates a little silent gap between each piece.

    I don't want to use streamed sound, only event/attached.

    If you press the "html" link I posted, you can try for yourself and see that when playing a piece in loop, it's perfect, but if looping with onSoundComplete, there is a sound gap. The dude who made punk o matic has no sound gabs and he doesnt use streamed sound AND he didnt want to say how he did it.


    Understand what I'm saying?

  13. #13
    Registered User
    Join Date
    Apr 2001
    Location
    Akron OH, USA
    Posts
    4,841
    ----
    I have splitted a 1 min song into 5 pieces. I want to rebuild that song in Flash by just playing up the next part when the previous is done playing.
    ----
    this was clear in your intial post.

    However, you did not explain why you need to do this. But anyway, perhaps someone else can help you.

  14. #14
    Amiga freak Ironclaw's Avatar
    Join Date
    Jan 2001
    Location
    Sweden
    Posts
    1,650
    It wouldnt be to any help if I explained why I need to do this.

    The reason why I want to do this is to make a song longer and the swf shorter. I have 5 parts which are about 200kb when published to swf.

    Each part is named 1 2 3 4 and 5.

    What I wanted to do if I could get rid of the sound gap is to make the song longer and keep the 200kb by using another sequence, like:

    1 2 4 4 4 5 2 2 1 4 5 etc.. the user wouldnt be able to tell when it started over from the beginning.

  15. #15
    Senior Member
    Join Date
    Jan 2003
    Location
    United States
    Posts
    892
    You might find then, the best solution might be to use an Audio Editor and custom make what you want. The Audio Editor could be the fastest and easiest way to accomplish this.

    It doesn't seem as if Flash can do what you desire by itself.
    When all is said and done -- "You MUST be Born Again!" John 3:3

  16. #16
    Amiga freak Ironclaw's Avatar
    Join Date
    Jan 2001
    Location
    Sweden
    Posts
    1,650
    Why would I use an audio editor? What help would that do?

    I have used an audio editor to cut the song into 5 perfect looping parts which I want to reproduce in flash.

    If you mean that I should use an audio editor for creating the sequence I want, like 4 3 2 2 5 1 2 1 4 etc... then that song would take alot more that 200kb, which those 5 parts does in Flash. If I knew how to get rid of the sound gap in Flash, I could make a 5 mins song taking only 200kb. You see what I mean?

    It doesn't seem as if Flash can do what you desire by itself.

    huh?, are you saying Flash cant attach part 1, and when that part is done, attach part 2.. etc? cuz I have done that using onSoundComplete, or havnt you read what I have written?
    Last edited by Ironclaw; 11-08-2004 at 07:43 AM.

  17. #17
    Member
    Join Date
    Feb 2002
    Posts
    57
    Ironclaw, have you figured out the answer to this problem? I am currently workin on a project that may require similar things though the actual delay is not as important to me as it is to you. I know exactly what you are trying to do. JWR is missing the point but its ok.

    im just curious if you have tried to build the whole thing using a time interval instead of making the code be frame rate dependant. I am toying with an idea in which the actual flash movie is not running (frames). And the thing that is dictating when sounds should play is code that is set to run on a set interval. Anyway, let me know if you want me to explain further.

    Btw, the reason he wants to loop 5 different parts of a song (im just repeating in diff words) is so that he can then loop part 1 20 times then move on to part 2 (no delay so it seams like the song never stopped), loop part 2 20 times then move on to part 3.. etc making his song last longer. If he makes an actual file with a sound editor like jwr is suggesting then yes the song would last as long as he wanted it to (5 min for ex) but then can u imagine how big the file size would be for a 5 min mp3 song? 10 min?

    Anyway i hope you havent given up on the idea since the last post is almost 3 months old. Let me know.
    : Nino ::-

  18. #18
    Registered User
    Join Date
    Apr 2001
    Location
    Akron OH, USA
    Posts
    4,841
    ---
    using another sequence
    ---
    Flash seems to be better at emulating a sequence by muting and unmuting a mix of loops rather than playing an actual sequence.

    Flash seems to introduce some latency before starting or restarting a sound from AS, which may be the cause for the gap. Because of this onsoundcomplete might not be a solution for effective sequencing, though I havent throughly explored this approach myself.

    All means of timing in flash are frame rate dependant (setInverval/enterFrame) and will not produce a consistent enough "clock" for syncing sounds in a rhythmically accurate way. I've tried to set up sequencers using setInverval, frame based loops and using frames themselves, and none ever worked in what I would call a musically effective way. I've also heard other attemps which in my opinion where not successful (unless they use the loop mixing technique see below)

    There is another technique for emulating a sequence by muting and unmuting sounds that are looping in sync simultaneously.

    The FAQ explains how to do this with using the sound edit window to set up a sequence of mutes and unmutes.

    It can be tedious and there is a limit to the number of times you can mute and unmute, but you will get the desired result as long as you can work with in the limits.

    I have been able to sequence sounds sucessfuly using the loop mixing technique.

  19. #19
    Registered User
    Join Date
    Apr 2001
    Location
    Akron OH, USA
    Posts
    4,841
    in summary, you can do sequencing by muting and unmuting looping sounds either from the sound edit window or AS.

    Muting and unmuting already playing sounds avoids the problem of trying start or restart sounds at a specific point in time to create a sequence. This is a problem because flash seems to introduce some latency at start or restart of a sound and flash does not seem to have a reliably accurate enough clock to schedule sound events in a rhythmically accurate way.

    Note that these views are based upon my experiences and observations of other's attempts at flash sequencing. There is always the situation where someone else figures out something or comes up with a new approach...

  20. #20
    Member
    Join Date
    Jul 2001
    Posts
    91
    An exact timer can be developed. The song object in flash only returns new values ~21 times a second, so I also start an interval, set to be called every 1 milisecond(which records a time with gettimer), but in actuality the interval is called in larger intervals due to the processor's inability. However, the interval returns new time values 100 times a second. (Windows XP SE, 2.6 Ghz, flash player 7) and the movie I am getting this data from is set to 12 fps. One can then keep a running average of the difference between the song.position, and the interval timer, then add that difference on to the timer to return accurate results of where the sound.position should be. Even more values can be returned if you have the interval calling the timer function, and an enterframe calling the timer function.

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center