Go Back   CodingForums.com > :: Client side development > Flash & ActionScript

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-02-2008, 02:02 PM   PM User | #1
gani
Regular Coder

 
Join Date: Nov 2008
Posts: 165
Thanks: 0
Thanked 0 Times in 0 Posts
gani is an unknown quantity at this point
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?
gani is offline   Reply With Quote
Old 12-02-2008, 02:56 PM   PM User | #2
gnomeontherun
Senior Coder

 
gnomeontherun's Avatar
 
Join Date: Sep 2007
Location: Houston
Posts: 2,846
Thanks: 10
Thanked 238 Times in 229 Posts
gnomeontherun will become famous soon enoughgnomeontherun will become famous soon enough
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.
__________________
jeremy - gnomeontherun
Educated questions often get educated answers, and simple questions often get simple answers.

Last edited by gnomeontherun; 12-02-2008 at 03:05 PM..
gnomeontherun is offline   Reply With Quote
Old 12-02-2008, 03:07 PM   PM User | #3
gani
Regular Coder

 
Join Date: Nov 2008
Posts: 165
Thanks: 0
Thanked 0 Times in 0 Posts
gani is an unknown quantity at this point
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.
gani is offline   Reply With Quote
Old 12-02-2008, 03:24 PM   PM User | #4
gnomeontherun
Senior Coder

 
gnomeontherun's Avatar
 
Join Date: Sep 2007
Location: Houston
Posts: 2,846
Thanks: 10
Thanked 238 Times in 229 Posts
gnomeontherun will become famous soon enoughgnomeontherun will become famous soon enough
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.
gnomeontherun is offline   Reply With Quote
Old 12-02-2008, 03:26 PM   PM User | #5
gani
Regular Coder

 
Join Date: Nov 2008
Posts: 165
Thanks: 0
Thanked 0 Times in 0 Posts
gani is an unknown quantity at this point
ok...will get back to you ..let me go and have a look see....
gani is offline   Reply With Quote
Old 12-02-2008, 03:56 PM   PM User | #6
gani
Regular Coder

 
Join Date: Nov 2008
Posts: 165
Thanks: 0
Thanked 0 Times in 0 Posts
gani is an unknown quantity at this point
strange ...it seems no one has ever done this before ...i thought it would be a common thing
gani is offline   Reply With Quote
Old 12-02-2008, 04:28 PM   PM User | #7
gnomeontherun
Senior Coder

 
gnomeontherun's Avatar
 
Join Date: Sep 2007
Location: Houston
Posts: 2,846
Thanks: 10
Thanked 238 Times in 229 Posts
gnomeontherun will become famous soon enoughgnomeontherun will become famous soon enough
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.
gnomeontherun is offline   Reply With Quote
Old 12-02-2008, 05:37 PM   PM User | #8
gani
Regular Coder

 
Join Date: Nov 2008
Posts: 165
Thanks: 0
Thanked 0 Times in 0 Posts
gani is an unknown quantity at this point
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
gani is offline   Reply With Quote
Old 12-02-2008, 10:15 PM   PM User | #9
gnomeontherun
Senior Coder

 
gnomeontherun's Avatar
 
Join Date: Sep 2007
Location: Houston
Posts: 2,846
Thanks: 10
Thanked 238 Times in 229 Posts
gnomeontherun will become famous soon enoughgnomeontherun will become famous soon enough
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.
gnomeontherun is offline   Reply With Quote
Old 12-03-2008, 10:05 AM   PM User | #10
gani
Regular Coder

 
Join Date: Nov 2008
Posts: 165
Thanks: 0
Thanked 0 Times in 0 Posts
gani is an unknown quantity at this point
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.
gani is offline   Reply With Quote
Old 12-03-2008, 12:24 PM   PM User | #11
gnomeontherun
Senior Coder

 
gnomeontherun's Avatar
 
Join Date: Sep 2007
Location: Houston
Posts: 2,846
Thanks: 10
Thanked 238 Times in 229 Posts
gnomeontherun will become famous soon enoughgnomeontherun will become famous soon enough
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.
gnomeontherun is offline   Reply With Quote
Old 12-04-2008, 09:39 AM   PM User | #12
gani
Regular Coder

 
Join Date: Nov 2008
Posts: 165
Thanks: 0
Thanked 0 Times in 0 Posts
gani is an unknown quantity at this point
There is no tutorial on cuepoints for actionscript 3 mp3 playback .. i have searched for days.

oh well.... thanks anyway Jeremy
gani is offline   Reply With Quote
Old 12-07-2008, 03:59 PM   PM User | #13
gani
Regular Coder

 
Join Date: Nov 2008
Posts: 165
Thanks: 0
Thanked 0 Times in 0 Posts
gani is an unknown quantity at this point
talk about ignorance...thanks jeremy...it seems your sent me what i was looking for in the first place
gani is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:09 PM.


Advertisement
Log in to turn off these ads.