Archive for the ‘tutorial’ Tag
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
Source (11Mb because of the WMV)
Part 2 of how to Create a video player in Silverlight 2
If you are having problems with the Slider not recoginzing MouseLeftButtonUp or MouseLeftButtonDown events, check out the VideoSlider