Thursday, May 21, 2009

Continous background music player in silverlight 2.0

Hi Friends,

This is a small example of how to incorporate background music for a website in silverlight 2.0, which will have continous stream of music, where you shuld make sure the editing of music is in such a  way that, you can feel as if it is continous.

Xaml code :

<MediaElement Height="34" Source="assets/bgmusic.mp3" MediaEnded="bgaudioplayer_MediaEnded"   Position="0" HorizontalAlignment="Right" Margin="0,0,44,227" VerticalAlignment="Bottom" Width="32" x:Name="bgaudioplayer"/>

C# backend code :

private void bgaudioplayer_MediaEnded(object sender, RoutedEventArgs e)
        {
            bgaudioplayer.Position = System.TimeSpan.FromSeconds(0);
            bgaudioplayer.Play();
        }


Cheers!
Muthaiah
www.fmass.com

2 comments:

Unknown said...

Your code doesnt work!!!

Fmass(Futuremass) said...

Hi this was with silverlight2 . May I know the version that you try?