Creating a video player in Silverlight is pretty simple. The MediaElement does all the heavy lifting, all you need to do is wire up a UI and you have a basic Video player. Here is a tutorial on how to create a simple video player from scratch using Silverlight 2.
- Create a Silverlight application
- Add a video to the project. This is for testing purposes only. Later in part 2 we will use a streaming video.
- Add a MediaElement and a Toggle button for Play/Pause of the video.XAML
- Add a Slider to show the position of the video. To show the progress of the video on the slider, we will need to create a DispatcherTimer. On the Tick event we will update the value of the slider. In this example I have set the value of the Tick to 50 milliseconds. There is minor jumping; if you want to get seamless indicator movment try going under 41 milliseconds. We also need to Start and Stop the timer. I am doing this on CurrentStateChanged event of the MediaElement.XAML
- Add a TextBlock to show the exact position of the video. To update the text, I am adding this to the Tick event of the timer.XAML
- Screen shot of the player at the end of Part 1

Links
Source (11Mb because of the WMV)
Part 2 of how to Create a video player in Silverlight 2
UPDATE
If you are having problems with the Slider not recoginzing MouseLeftButtonUp or MouseLeftButtonDown events, check out the VideoSlider






April 2nd, 2008 at 1:45 pm
[...] Create a Video Player in Silverlight 2 - Part 1 (Corey Schuman) [...]
April 15th, 2008 at 2:15 am
[...] a video player Silverlight 2 - Part 2 Posted April 15, 2008 In part 1 we covered setting up a very basic video player. In part 2 we will [...]
April 15th, 2008 at 12:37 pm
A nice clean simple example. Thanks. I must try this out.
Very few major sites seem to be using Silverlight though, must stick with Flash, one of the few I’ve seen is ITV.com
April 21st, 2008 at 7:19 pm
[...] Create a video player in Silverlight 2 - Part 1 [...]
April 21st, 2008 at 7:33 pm
[...] Create a video player in Silverlight 2 - Part 1 [...]
April 29th, 2008 at 1:18 pm
I have problems with this when I try to load the wmv file without a path. When I add the full url to the filename on the Source property then it works. (ie Source = “http://localhost:53018/bear.wmv”)
How did you get it to load the file from the filesystem? I got a weird error:
sys.invalidoperationexception: mediaerror error #1001 in control ‘Xaml1′ AG_E_Unknown_error
Thanks for the walkthrough!
cheers,
stephen
May 1st, 2008 at 2:30 pm
Hey Stephen,
Are you trying to set the Source from C#? If so you will need to use the Uri object. Try something like mediaElement.Source = new Uri(”http://localhost:53018/bear.wmv”, UriKind.Absolute);
June 3rd, 2008 at 8:07 pm
Why the hell there is not a ProgressEvent????
We have DownloadProgressChange event AND BufferingProgressChange event but NO VideoProgressChange event!
WTF!?
dummy silverlight…
June 13th, 2008 at 3:29 pm
Hi Stephen
This tutorial is fantastic.
I’ve developed a Video Player:
http://www.silverlight-blog.it/ontheroad/videoplayer/index.html
Mino
July 3rd, 2008 at 3:38 am
Don’t forget to set build action “Resource” while adding video file to the project…
October 3rd, 2008 at 8:41 pm
[...] Create a video player in Silverlight 2 - Part 1 [...]
October 11th, 2008 at 11:10 am
Thanks for sharing , useful information. 244
October 21st, 2008 at 9:32 am
[...] am busy with a Silverlight video player at the moment, and what is interesting to note and understand is that Silverlight is heavily [...]
December 10th, 2008 at 4:42 pm
The “Source” code link isn’t working. Thx.
May 4th, 2009 at 9:25 pm
nice……………………..
May 27th, 2009 at 10:13 pm
I don’t know why Silverlight application can not load the video in the
folder Video of project (Video/ds22.wmv). I have tried to add full url(ex:http://localhost:1805/Video/ds22.wmv or file:///C:/Documents and Settings/Administrator/My Documents/Visual Studio 2008/Projects/MediaPlayer/MediaPlayer/Video/ds22.wmv ) of this video in C# that this way is said above but it even does not work.
Can somebody help me to resolve this problem.
Thanks
June 28th, 2009 at 11:29 am
how about add extra function such as load/open a video file from hardisk into the video player? can anyone teach me that? i have to complete my final year project ASAP.. please~~
June 30th, 2009 at 6:09 am
The file must be a resource. Add the file of movie and click right on movie; select properties and at build action select “Resources”.
September 10th, 2009 at 2:30 pm
Hi! I was surfing and found your blog post… nice! I love your blog.
Cheers! Sandra. R.
September 11th, 2009 at 10:52 am
Sign: umsun Hello!!! rcuwwymhyw and 8328ssgfhphzye and 3831Nice blog!
September 29th, 2009 at 9:32 am
Thank your topic. I like its. Must try it now.
January 22nd, 2010 at 12:08 am
[...] my Silverlight 4 book as well as at work. Creating a basic video player is straight forward (link 1 | link 2), have a button to play, a way to control the volume, a scrubber to show the position of [...]
January 22nd, 2010 at 2:28 am
[...] my Silverlight 4 book as well as at work. Creating a basic video player is straight forward (link 1 | link 2), have a button to play, a way to control the volume, a scrubber to show the position of [...]
April 15th, 2010 at 12:49 pm
Hi.I can’t download the source code. The link don’t work..
May 27th, 2010 at 1:43 am
Howdy there,I obtain that your blog is incredibly informative and useful and we were curious if there is really a possibility of obtaining More articles or blog posts like this on your site. If you willing to assist us out, we will be willing to compensate you… Sincerely, Noma Carrier
May 31st, 2010 at 4:08 am
hey,Fantastic blogging dude! i am just Tired of using RSS feeds and do you use twitter?so i can follow you there:D.
PS:Have you thought to be putting video to your web site to keep the readers more enjoyed?I think it works.Best wishes, Darren Steeley
June 1st, 2010 at 10:59 am
[...] working on a tutorial to build a media player in Silverlight and am trying to wire up an EventHandler to the timer.Tick event of a DispatchTimer object so that [...]
July 31st, 2010 at 6:22 am
— “Who knows H264 Player for Silverlight?”— Hi all experts out there. We have ordered a development of a video application on Silverlight and our developer’s R&D people tell us that they cannot find ANY player that plays H264 on Silverlight. Is this possible? can you explain why? what should we do? is anyone working on having such a player soon? many thanks.