-
KoolMoves Moderator
Sound syncing Project - Completed Download Avail
Ok I'm working on something. I've made a little program that lets you generate an array of markers for an MP3 file that you can import into KM.
I'm trying to figure out the best way to now track the sound and trigger events based on the markers.
Right now I'm generating the following code
markerArray=new Array("2631","one","6269","two","10031","three");
where the number is the position in the song and the next item is the action or label
Any AS guru's want to help point me in the right direction?
-
KoolMoves Moderator
Here's what I've got so far and it seems to work
code:
_global markerArray=new Array("2563","one","6273","two","10100","three");
mySound=new Sound()
mySound.loadSound("scenes.mp3",false);
mySound.onLoad=function(){
mySound.isLoaded=true
mySound.start()
c_marker=markerArray.shift()
txt3.text=c_marker
c_action=markerArray.shift()
}
markers=function(audio){
pos=audio.position;
txt1.text=pos
checkIt(audio)
}
checkIt=function(audio){
if (audio.position>=c_marker){
txt2.text=c_action
c_marker=markerArray.shift()
//txt3.text=c_marker
c_action=markerArray.shift()
}
}
setInterval(markers,1,mySound)
stop()
I think it might be better if I could use listeners that and some sort of EVENT system. I hope Wilbert sees this and I can pick his brain.
Last edited by blanius; 03-31-2006 at 11:31 PM.
-
Bret,
Can you be a bit more specific what kind of listener function you had in mind ?
Maybe this old thread can also be of some help
http://www.flashkit.com/board/showth...hreadid=623645
Wilbert
-
KoolMoves Moderator
That's pretty much what I had in mind.
I don't quite understand it, you use features that I don't understand......
I could make the program I made output code like you have
mySoundEvents.push ( { sp:1500, o:_root.mc1, f:'gotoAndStop', p:['eeks'] } );
mySoundEvents.push ( { sp:2000, o:_root.mc1, f:'gotoAndStop', p:[1] } );
mySoundEvents.push ( { sp:3000, o:_root.mc2, p:'_visible', v:false } );
mySoundEvents.push ( { sp:3500, o:_root.mc2, p:'_visible', v:true } );
Maybe I don't need to understand your code so much as appriciate at and make use of it.
I hadn' thought of assigning object and paramaters to the event, I was just using markers. I didn't realize that could be done.
-
There's so many ways one can implement such a synchronization routine.
Another way could be to implement an onPos event....
Code:
// Extending the sound object
// syncStart([secondOffset:Number], [loops:Number], [msecAccuracy:Number])
Sound.prototype.syncStart = function(){
var f;
this._ev = [];
for (f in this) if (f.substr(0,5) == 'onPos' || f.substr(0,5) == 'onpos') this._ev.push({p:f.substr(5),o:this[f]});
this._ev.sortOn('p',Array.NUMERIC);
this._ce = 0;
if (this._id != null) clearInterval(this._id);
this._id = setInterval(this, '_sync', arguments.length > 2 ? arguments[2] : 100);
this.start.apply(this,arguments);
}
Sound.prototype._sync = function(){
if (this.position >= this._ev[this._ce].p){
this._ev[this._ce].o.apply(this);
if (this._ce++ == this._ev.length) clearInterval(this._id);
arguments.callee.apply(this);
}
}
// using it
mySound = new Sound();
mySound.loadSound('myMP3file.mp3',true);
mySound.onPos5500 = function(){ _root.txt1.text = '5.5 seconds passed'; }
mySound.onPos6500 = function(){ _root.txt1.text = '6.5 seconds passed'; }
mySound.syncStart();
Notes:
- It only works the first time the sound plays if you use a sound from the symbol library and loop it. If you want it to work for each loop you have to modify the code.
- Another possible problem is if you implement forward and backward buttons so the user can jump back. Again, in that case you would have to modify the code to calculate the new _ce value (current event).
- Flash 7 is required for numeric sorting of arrays.
Wilbert
-
KoolMoves Moderator
Playing with the code from your other thread but can't get it to work.
Have stopped movie with four frames as mc1 in root. Frame 2-4 are named one, two, three
code:
update=function(){
_root.txt1.text=_root.mySound.position
}
setInterval(update,50);
/ Extending the sound object
Sound.prototype.setSoundEvents = function( events, accuracy ){
_root.txt1.text=this.position
this.events = events;
this.current_event = 0;
if (this.interval_id != null) clearInterval(this.interval_id);
this.interval_id = setInterval(this, 'sync', accuracy);
}
Sound.prototype.sync = function(){
if (this.position >= this.events[this.current_event].sp){
var event = this.events[this.current_event];
if (event.f != null){
var func = event.o[event.f];
func.apply(event.o, event.p );
} else if (event.p != null){
event.o[event.p] = event.v;
}
this.current_event = this.current_event + 1;
if (this.current_event == this.events.length) clearInterval(this.interval_id);
this.sync();
}
}
// using it
mySoundEvents = new Array();
mySoundEvents.push ( { sp:2660, o:_root.mc1, f:'gotoAndStop', p:['one'] } );
mySoundEvents.push ( { sp:6383, o:_root.mc1, f:'gotoAndStop', p:['two'] } );
mySoundEvents.push ( { sp:10090, o:_root.mc1, f:'gotoAndStop', p:['three'] } );
mySoundEvents.sortOn('sp');
mySound = new Sound();
mySound.setSoundEvents( mySoundEvents, 10 ); accuracy 50 msec
mySound.loadSound('Scenes.mp3',true);
mySound.start();
Last edited by blanius; 04-01-2006 at 11:07 AM.
-
KoolMoves Moderator
Also if you wanted the object to be _root would you put _root in the o:?
Some of this syntax is very hard to follow.
-
Yes, you would put _root in there.
I don't understand why it doesn't work. If I copy the code you post it doesn't work, if I copy the code from the original thread it does
-
KoolMoves Moderator
very odd...... Only thing I changed was some of the array elements and the name of the mp3 file. What else could have changed I wonder.
Trying to debug I notice that if I look at mySoundEvents[0].sp it's the last marker not the first if I comment out the mySoundEvents.sortOn('sp'); it's the first marker. shouldn't it be the first one?
-
KoolMoves Moderator
can you explain this line more?
func.apply(event.o, event.p );
how does this work? apply is not a keyword is it? Hard to debug when I can't quite understand what you've done.
-
Originally Posted by blanius
can you explain this line more?
func.apply(event.o, event.p );
how does this work? apply is not a keyword is it? Hard to debug when I can't quite understand what you've done.
As for your previous post, When testing the original code I didn't encounter the sort problem since I only seem to have used values between 1000 and 9999. To get a correct sort at all times you should use a numeric sort like I did in the other code example.
apply is a keyword !
You can look it up in the actionscript dictionary (see Function).
If you have a function, you can apply it to an object and pass a parameter array. In this case func contains the function. The object is will consider 'this' is event.o and the array that contains the parameters is event.p .
-
KoolMoves Moderator
BINGO that does it. Ok this works now. I'll rewrite my utility to generate this style of array.
-
KoolMoves Moderator
Ok who wants to test it?
file removed download the Zip file
Example of sync audio
http://bretlanius.com/flash/markers.html
to use it paste the generated code into
code:
Sound.prototype.setSoundEvents = function( events, accuracy ){
this.events = events;
this.current_event = 0;
if (this.interval_id != null) clearInterval(this.interval_id);
this.interval_id = setInterval(this, 'sync', accuracy);
}
Sound.prototype.sync = function(){
if (this.position >= this.events[this.current_event].sp){
var event = this.events[this.current_event];
if (event.f != null){
var func = event.o[event.f];
func.apply(event.o, event.p );
} else if (event.p != null){
event.o[event.p] = event.v;
}
this.current_event = this.current_event + 1;
if (this.current_event == this.events.length) clearInterval(this.interval_id);
this.sync();
}
}
// using it
mySoundEvents = new Array();
/****************************Paste the code here********************/
mySound = new Sound();
mySound.setSoundEvents( mySoundEvents, 10 ); accuracy 50 msec
mySound.loadSound('scenes.mp3',true);
mySound.start();
stop()
Last edited by blanius; 04-21-2006 at 11:09 PM.
-
Thank you Bret! How did you know I needed help with a sound sync project? This really has helped. I did notice when resetting the sound the counter does not return to zero. Thanks again Bret
-
KoolMoves Moderator
Yeah I don't know why. I assume that the MCI interface in Windows is not reporting it correctly.
-
KoolMoves Moderator
Forgot to put back the track bar for the mp3, this lets you back up or jump forward when you need to. Also put together example fun and doc explaining how to use.
Finished project here:
http://koolexchange.com Look under Tools.
Last edited by blanius; 07-08-2006 at 01:04 PM.
-
KoolMoves Moderator
If anyone uses this to make something please share it with us. I know I really enjoy it when someone gets something usefull from my efforts. I spend alot of time working things out but never get to see what people are doing with it.
-
Bret I tried out your MP3 Marker and it worked like a charm! This is just a quick sample. The mouth movements are just open and closed. http://home.att.net/~pos3sum/toad/mark1.html
Thanks Bret
-
KoolMoves Moderator
-
And the "KoolMan" medal for best code and DOCUMENTATION goes to ..... (wait 22 seconds before you read on) ...... (you're still waiting, right?) ..... Bret Lanius and the gang! TADA - drum roll
Thanks Bret, that's a great project that will come in handy sooner or later here too. Sorry I haven't posted much ... things are crazy here. Yesterday I was on TV .... life is good. Why am I telling you this? lol
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|