Media player for Windows 7 Mobile


This article will give step to step illustration of creating a simple media application for Windows 7 mobile.

Step 1

Create a new Windows Phone Application. From Silverlight for Windows Phone tab select Windows Phone Application project type.


Step 2

Design page.

  1. Divide content grid in two rows
  2. In first row put a media element control
  3. In second row put a button.


    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="800"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush

    <Grid x:Name="LayoutRoot" Background="{StaticResource PhoneBackgroundBrush}">
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>

        <!--TitleGrid is the name of the application and page title-->
        <Grid x:Name="TitleGrid" Grid.Row="0">
            <TextBlock Text="Windows 7 phone" x:Name="textBlockPageTitle" Style="{StaticResource PhoneTextPageTitle1Style}"/>
            <TextBlock Text="Media" x:Name="textBlockListTitle" Style="{StaticResource PhoneTextPageTitle2Style}"/>

        <!--ContentGrid is empty. Place new content here-->
        <Grid x:Name="ContentGrid" Grid.Row="1">
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
            <Button x:Name="btnPlay" Content="Play" Height="50" Width="100" Grid.Row="1" />
            <MediaElement x:Name="mediactrl" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Stretch="Uniform" Grid.Row="0"/>

Step 3

Right click on project and add an existing .wmv in project. I am adding a.wmv file here.

Step 4

Now in code behind just play the media

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

namespace PhotoApplication
    public partial class MainPage : PhoneApplicationPage
        public MainPage()

            SupportedOrientations = SupportedPageOrientation.Portrait | SupportedPageOrientation.Landscape;
            btnPlay.Click += new RoutedEventHandler(btnPlay_Click);

        void btnPlay_Click(object sender, RoutedEventArgs e)
            mediactrl.Source = new Uri("a.wmv", UriKind.Relative);


Press F5 to get the output.


I hope this article was useful. Thanks for reading. Happy coding.

Up Next
    Ebook Download
    View all
    View all