Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    Regular Coder
    Join Date
    Nov 2008
    Posts
    165
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Add event listener to playback

    I have the following actionscript which plays an mp3.


    Code:
    var s:Sound = new Sound();
    var sc:SoundChannel;
    
    s.load("my_song.mp3");
    sc = s.play();
    
    import flash.external.ExternalInterface;
    ExternalInterface.call("alert", sc.position);
    I want the alert call to be activated every 100ms during the playback. I have no idea how to do this. I need to add some sort of eventlistener to the playback so that it triggers the alert every 100ms... Any ideas?

  • #2
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    If you just want to have a function repeat, then do something like this:

    Code:
    updateMarker = setInterval(functionname,100);
    http://www.adobe.com/support/flash/a...ionary646.html

    The only trick then would be to make sure that when the audio stops to clear the interval so it stops running repeatedly.

    Code:
    clearInterval(updateMarker );
    http://www.adobe.com/support/flash/a...ionary141.html

    I'll post more later when I have Flash files around with examples of listeners.
    Last edited by gnomeontherun; 12-02-2008 at 04:05 PM.
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #3
    Regular Coder
    Join Date
    Nov 2008
    Posts
    165
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That wouldn't work.... if anything happens to the playback ... then the alerts will continue coming. Or if the playback is delayed a bit ...the alerts will come out of sync.

  • #4
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    Ok, I didn't know exactly what the function was meant to do, I assumed it was something like adjusting the marker position or something like that.

    Anyways have you looked at the audio tutorials at www.gotoandlearn.com? I suggest those first, because they can better explain with visuals!
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #5
    Regular Coder
    Join Date
    Nov 2008
    Posts
    165
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok...will get back to you ..let me go and have a look see....

  • #6
    Regular Coder
    Join Date
    Nov 2008
    Posts
    165
    Thanks
    0
    Thanked 0 Times in 0 Posts
    strange ...it seems no one has ever done this before ...i thought it would be a common thing

  • #7
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    I haven't done it before, and I was having trouble finding good documentation on AS2 scripts. Here is something though.

    http://www.adobe.com/devnet/actionsc..._audio_02.html

    http://flash-reference.icod.de/Sound.html
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #8
    Regular Coder
    Join Date
    Nov 2008
    Posts
    165
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok, half of that was impossible for my pea brain to understand... the other half did not have what i was looking for.

    I guess the only solution, which i was trying to avoid is to do a setInterval which will run every 50ms to check the playback position. If the playback position is within certain limits then it will alert the message.

    I wish i had found a more intelligent work around though

  • #9
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    The first article is a bit complex I understand, but it covers making a class which is then used to provide information about the audio file. Are you planning on streaming this audio? I would think that if you buffer the item it would be fine in most situations, but what are you sending to the alert?

    Also there is a .onSoundComplete event which allows you to clear the interval when this occurs, so the alert stops.
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #10
    Regular Coder
    Join Date
    Nov 2008
    Posts
    165
    Thanks
    0
    Thanked 0 Times in 0 Posts
    the alert will actually be a gotoandStop function which will show a particular frame depending on the position of the sound being played. I know this can be done in AS3... but this is an AS2 solution.

  • #11
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    You could use cue points in the audio file (which is the first that I liked to, which is likely the one that caused you some headaches), and here is a great guide to audio (without cues) that I just came across. I just can't find any good resources either for cues besides that one article.


    http://www.kevinminke.com/?p=3
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #12
    Regular Coder
    Join Date
    Nov 2008
    Posts
    165
    Thanks
    0
    Thanked 0 Times in 0 Posts
    There is no tutorial on cuepoints for actionscript 3 mp3 playback .. i have searched for days.

    oh well.... thanks anyway Jeremy

  • #13
    Regular Coder
    Join Date
    Nov 2008
    Posts
    165
    Thanks
    0
    Thanked 0 Times in 0 Posts
    talk about ignorance...thanks jeremy...it seems your sent me what i was looking for in the first place


  •  

    Posting Permissions

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