---
title: "MediaElement Control in Windows 7 Phone Development"  
description: "When beginning a media-based application for Windows Phone, perhaps the easiest thing to do is to use the Silverlight MediaElement control. With just"  
author: "Anonymous User"  
published: 2012-04-13  
updated: 2019-09-07  
canonical: https://www.mindstick.com/articles/920/mediaelement-control-in-windows-7-phone-development  
category: "windows phone"  
tags: ["windows phone"]  
reading_time: 2 minutes  

---

# MediaElement Control in Windows 7 Phone Development

When beginning a media-based [application](https://www.mindstick.com/articles/12824/calculator-application-in-android) for Windows Phone, perhaps the easiest thing to do is to use the [Silverlight](https://www.mindstick.com/blog/54/silverlight-in-asp-dot-net) MediaElement control. With just a few lines of code, you can easily play or [stream video](https://answers.mindstick.com/qa/49858/how-to-stream-video-from-a-mac-to-xbox) in your Windows Phone Application. This article is going to explain how to use MediaElement control in Windows 7 Phone development.\

##### Getting started:

1. Open [Visual Studio](https://www.mindstick.com/articles/12378/visual-studio-for-mac-is-out-of-beta-preview-now-officially-available)

2. Create new Silverlight Windows 7 Phone [Development Project](https://www.mindstick.com/blog/11637/how-to-choose-the-right-web-designer-for-your-web-design-development-project)

3. Enter [your project](https://www.mindstick.com/forum/156583/best-way-to-link-bootstrap-file-in-your-project) Name

4. Click on button ‘Ok’

![MediaElement Control in Windows 7 Phone Development](https://www.mindstick.com/mindstickarticle/b22e403e-b633-459c-956a-b6db16a64cfe/images/bf5a6a7f-4f76-4628-81b6-bab995abe88d.png)

Now drag and drop MediaElement control form toolbox into MainPage.xaml design page; after doing this set media path by selecting **Source** property of MediaElement control.

![MediaElement Control in Windows 7 Phone Development](https://www.mindstick.com/mindstickarticle/b22e403e-b633-459c-956a-b6db16a64cfe/images/6e1424e4-95be-40b2-84e9-ad40043045ee.png)

Now write down the following code to build this layout;

##### Code of ‘MainPage.xaml’:

```
<!--LayoutRoot is the root grid where all page content is placed-->    <Grid x:Name="LayoutRoot" Background="Transparent">        <Grid.RowDefinitions>            <RowDefinition Height="Auto"/>            <RowDefinition Height="*"/>        </Grid.RowDefinitions>         <!--TitlePanel contains the name of the application and page title-->        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">            <TextBlock x:Name="ApplicationTitle" Text="My Application" Style="{StaticResource PhoneTextNormalStyle}"/>            <TextBlock x:Name="PageTitle" Text="MediaElement Demo" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>        </StackPanel>         <!--ContentPanel - place additional content here-->        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">            <MediaElement Height="433" HorizontalAlignment="Left" Margin="12,0,0,140" Name="mdElementDemo" VerticalAlignment="Bottom" Width="438" />        </Grid>    </Grid>
```

Code of ‘MainPage.xaml.cs’:

```
using System;using System.Windows;using Microsoft.Phone.Controls;using Microsoft.Phone.Tasks; namespace MediaElementDemo{    public partial class MainPage : PhoneApplicationPage    {        // Constructor        public MainPage()        {            InitializeComponent();             this.Loaded+=new RoutedEventHandler(MainPage_Loaded);        }         void MainPage_Loaded(objectsender, RoutedEventArgse)        {            MediaPlayerLauncher launcher=new MediaPlayerLauncher();             launcher.Media=new Uri("http://www.robtowns.com/music/blind_willie.mp3", UriKind.RelativeOrAbsolute);            launcher.Controls= MediaPlaybackControls.All;            launcher.Show();        }           }}
```

\

Now execute [your program](https://answers.mindstick.com/qa/33494/how-do-you-find-any-view-element-into-your-program-explain-for-example) then following [output window](https://www.mindstick.com/forum/160484/error-failed-to-launch-debug-adapter-additional-information-may-be-available-in-the-output-window) will be appearing.

![MediaElement Control in Windows 7 Phone Development](https://www.mindstick.com/mindstickarticle/b22e403e-b633-459c-956a-b6db16a64cfe/images/712b2857-b1bf-4791-9797-08f4e4b15aba.png)

![MediaElement Control in Windows 7 Phone Development](https://www.mindstick.com/mindstickarticle/b22e403e-b633-459c-956a-b6db16a64cfe/images/d30b8752-f921-4ae0-a28e-cf692c7576ad.png)

This is the complete description about Media Control in Windows Phone 7. I hope you will be enjoying it. Thanks for reading this article.

\

---

Original Source: https://www.mindstick.com/articles/920/mediaelement-control-in-windows-7-phone-development

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
