Trigger .PLAY of Media Elements on dynamic Timeline?
I'm a total newbie to Silverlight... I have a question regarding an application...
Given any number of .WMA (<5sec sound effects) loaded as Media Elements. I wish to create an application that will generate a list of these effects associated with a specific time... such that when it "plays" the sound file effects kick-off at the time pre-determined time (resolution within a few miliseconds).
Can a "Timeline" be defined dynamically and the files assigned a position in time on the Timeline so that these .WMA files playback at the associated time along the timeline? (BTW, Timeline not to exceed 20 sec.)
This idea is the result of reading the MSDN Class library docs... so I may be way off.
If anyone has a suggestion of how to implement this (at the desired resolution), that would be great... sample code would even be BETTER!
Thank you for your help!
-charlie
hello.
can you give more details on waht you're trynig to do? do you want to create a dynamic animation and associate it with an existing xaml object? what should the animation do?
Hi Luis, thank you for your reply.
Not an graphics animation at this point, just need to playback sound files at specific times. So, within a 20 sec window (maybe a Timeline or a Storyboard, I'm not sure) I need to dynamically place sound files for playback - then run it. The sound files should then play in sequence at their associated time... with resolution within a few miliseconds. This may later involve graphics animation, where vector based art will appear in sync with the sound files... the key here is that it is dynamically created (by the user).
I would think this could be done... an example would be great!
Thanks for your help and interest.
-charlie
hello.
well, i think you can't load a playlist in the current version. that being the case, you'll have to use several mediaelements to load each sound and then you'll have to start the playing manually. mybe you can do this by using a timer from jscript?
I guess what I was thinking was... you're suppose to be able to create animation against some sort of Timeline or Storyboard using Expression Blend... and it produces XAML output... so why couldn't I write an app that produces the same output except for variable files at variable times (inside the Timeline or Storyboard function)?
Maybe these don't end up Media Elements, maybe they end up and Element inside the Storyboard (or whatever).
I guess being so unfamilar with the product, I don;t want to reinvent the wheel...
How does vector graphics and individual sound files (sound effects) on some sort of timeline work? If anything like FLASH, I'd have a Timeline and frames that I would attach graphics and sound to... then the playback syncs the elements to create the animation...
I guess all I want to do is remove the static interface for a dynamic one.
Thoughts?
-charlie
Hello Charlie.
well, i guess things are a little different with silverlight. I've just started looking at it now too, but i've noted that here you have more flexibility in the way you define your timelines and storyboards but there's also more complexity in performing the kind of thing you want to do. for instance, animations are allways related with changing the value of a property (which is really the same principle you follow when you use flash), but with wpf/, there's not an easy way to drop a mp3 file on the movie and make it start playing. in order to do that, i really think that you'll have to write javascript code and maybe interact with animations (though I'm not sure if animations will help you in this scenario...)
Luis,
Well if this is true, than it's as impressive as FLASH... I mean ActionScript is a pain... so what's the benefit if I have to write js (other than js is more comonly known). Geee, I'm disappointed.
Am I correct that Miscrosoft Expression BLEND would be the front-end tool to create animations... and these animations are output as XAML? I might look into this further... can you send me a code snippet, or some pseudo code of what you're suggesting?
If I have to code what clocks or timers are available to me using the Silverlight plugin (?)... could I use the Framework2 or 3 "Stopwatch" not sure how it would hook into the page though...
Thanks for your help!
-charlie
Hello again.
Blend might help you with developing animations. the only problem I've seen is that it's really meant to be used in WPF interfaces, where you have styles, templates, bindings, etc. Regarding the js timers I've mentioned, I suggested taking a look at the window.setInterval and window.setTimeout methods (they're similar, but the 1st one will call your code fomr x to x seconds while the 2nd will only do that once after x seconds have ellapsed).
btw, can you present a simple scenario which is similar to what you want? I mean, a complete description like: i have a line which is streched until coord 100. then sound x should start playing followed by sound Y. Then a rectangle should appear, bla bla bla. Do you have a simple example that you can completly describe? maybe by seeing that I'll be able to get a better idea and suggest other options? (or maybe not...who knows...)
Hi Luis, I appreciate all your responces!
I'll look at what you're suggesting - just remember I need millisecond resolution so the "x seconds" might not work...
As far as the example:
Here are the elements that maybe would download with the page:
GlassBreak.wma
MansCough.wma
WomansSneeze.wma
DoorBell.wma
1. User is prompted to (I dun'no) randomly click his mouse for the next 20 seconds ...
Program starts some sort of timer (maybe like .stopwatch) and assigns the elasped time found at every mouse click until 20 sec. has elapsed - then the mouse-click capture ends - resulting in an array or "list" of intervals.
2. Program randomly assigns any of the above 4 .wma files to each of the captured times, generates the necessary code (XAML?) and links the code to a command button for the user to click when ready for "playback".
3. User presses the button to playback the randomly selected .wma's at the exact (within a few miliseconds) of when the mouse was previously clicked and captured the elasped time.
This is just a silly example - no, I don't just want to tie the click directly to the element... the whole idea is to have timing data (however it is generated, recorded, etc.) and then have it assigned to .wma files to playback within a few milliseconds of the actual assigned time.
Animations like color change, objects appearing/disappearing, etc. may also be added for the "experience"...
If this is possible... I'd really like to see some code... I can't imagine that this is too difficult.
Thanks for your interest and your help!
-charlie
hello again.
sorry for the late reply, but I've been called to solve a problem wtih an app...
in that scenario, i'd do everything from js (ie, the capturing of the time would be saved in js). i'd do something like this:
1. save in a variable the current date when the process of clicking starts and set a variable to true (saying that it's ok to capture the clicks and save the time)
2. call settimeout method specifying the total duration of the interval
3. during a click, i'd save the current date time in an array and i'd keep doing this until the interval ends or the max number of clicks has been reached (in this case, you'd have to cancel the settimeout method call you've performed)
now, calculating the start of each wav file is as simple as getting the difference between the date you've saved in the beginning of the process and each click you've saved.
Thank you Luis,
But I'm not trying to solve the capture problem... I'm trying to solve how to playback .wma at specific (millisecond resolution) time. Don't want to use date functions, as who knows if some system date will change during a capture... so, some sort of timer is the answer.
I keep going back to a XAML generated Storyboard where the MediaElements are set to a specific frame in time. Maybe I just need to buy BLEND, attach some .WMA's to a animation, generate the code, and look at it...
Would anyone out there in Silverlight/Blend land do this for me?
-charlie