Introduction:
In this article we are going to see how to use media framework which helps the application developers to stream video and audio files and to use the integrated Music and video Hubs to select the media files. In our earlier articles we have seen the different controls to design a rich user experience application and today in this topic we will see much more interesting aspects on handling the media files which will be very effective for using in a Mobile device.
Media in windows phone 7 uses the MediaElemt API to incorporate the audio and video files using the inbuilt device media player in Silverlight for Windows Phone 7 Application. In this article we will see how to play a video file using the MediaElement API with windows phone 7 application development. Let us see the step by step process on how to use the Media development in Windows phone 7 application using the MediaElement API. [more]
Steps:
Open Visual Studio 2010 and create a new Silverlight for Windows Phone 7 application project by providing a valid project name as shown in the screen below.
Now let us customize the Mainpage.XAML by adding a button control and a MediaElement to play the video file as shown in the screen below. Also we have customized the header grid to have a unique design for this series of articles.
XAML Code:
|
|
|
|
|
|
|
|
Now let us add a sample video file to the project which we will load on click of the button. We have added a sample .WMV file to the root folder of the project once we added the file now go to the button click event (Play Video button) and write the below code to stream the video file on button click as shown in the below screen.
XAML Code:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
C# Code:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Now we are done with our code, let us build and execute the application by directly pressing the F5 button from the keyboard or by selecting the Build and Execute option from the tool bar. We can see the output of the application as shown in the screen below.
Now we can see the video streaming as shown in the above screen, with the option to restart and reset the video at any point of time. We can also customize to select the file randomly and play as we normally do using the playlists which we can see in depth in our upcoming articles.
Conclusion:
So in this article we have seen how to use the Media Element to stream video files and use it effectively. We will see in depth on the property available to make a customized video player in our upcoming articles.
No Comments
Hardly can I believe that such faultless blogs exist.
bookmarked!!, I love your site!|
What are the properties available in that element and how to use those effectivly??