views:

329

answers:

3

I'd like to create to some custom visualization effects to a sound wave in Silverlight. As of Silverlight 3 there's the MediaElement class which does a great job in playing sounds/videos.

To visualize however I would need some kind of event callback with some information on the currently played segment of the sound. Does the framework have some support for achieving this?

+1  A: 

Sadly this is not possible in Silverlight unless you go the whole way and create your own MediaStreamSource to decode the audio (e.g. from MP3) yourself.

Can you get away with cheating? A lot of web players show a fake graphic equaliser which just has bars going up and down randomly during playback. I seem to remember that MySpace and SoundClick used to do this (may still do).

Mark Heath
I don't want to cheat but thanks for the hint :)
Gergely Orosz
+1  A: 

If you implement a custom MediaStreamSource, you could potentially inspect/analyze the data being generated by it, but you will immediately run in to UI threading issues if you try and update the UI directly from the custom MediaStreamSource, or vice versa.

One way to get this to work might be to implement a custom MediaStreamSource that writes (or duplicates?) extra audio data to a thread-safe buffer where your UI could access it.

Mike Hodnick
+4  A: 

I wanted the same so I've created exactly that. You can see a live demo at http://prefix.teddywino.com/post/SilverlightMediaKitLiveDemo.aspx

The library and demo source code are available at http://salusemediakit.codeplex.com/ The demo shows the added feature to alter the raw audio data to create effects. Currently works only with MP3s and is still under development

theahuramazda