Objective
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.
- Divide content grid in two rows
- In first row put a media element control
-
In second row put a button.
MainPage.Xaml
<phoneNavigation:PhoneApplicationPage x:Class=”PhotoApplication.MainPage” xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:phoneNavigation=”clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Navigation” xmlns:d=http://schemas.microsoft.com/expression/blend/2008 xmlns:mc=http://schemas.openxmlformats.org/markup-compatibility/2006 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}”> <Grid.RowDefinitions> <RowDefinition Height=”Auto”/> <RowDefinition Height=”*”/> </Grid.RowDefinitions> <!–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}”/> </Grid> <!–ContentGrid is empty. Place new content here–> <Grid x:Name=”ContentGrid” Grid.Row=”1″> <Grid.RowDefinitions> <RowDefinition Height=”*” /> <RowDefinition Height=”Auto” /> </Grid.RowDefinitions> <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″/> </Grid> </Grid></phoneNavigation:PhoneApplicationPage> |
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 write below code to play the media file
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Net;
5 using System.Windows;
6 using System.Windows.Controls;
7 using System.Windows.Documents;
8 using System.Windows.Input;
9 using System.Windows.Media;
10 using System.Windows.Media.Animation;
11 using System.Windows.Shapes;
12 using Microsoft.Phone.Controls;
13
14 namespace PhotoApplication
15 {
16 public partial class MainPage : PhoneApplicationPage
17 {
18 public MainPage()
19 {
20 InitializeComponent();
21
22 SupportedOrientations = SupportedPageOrientation.Portrait | SupportedPageOrientation.Landscape;
23 btnPlay.Click += new RoutedEventHandler(btnPlay_Click);
24 }
25
26 void btnPlay_Click(object sender, RoutedEventArgs e)
27 {
28
29 mediactrl.Source = new Uri(“a.wmv”, UriKind.Relative);
30 mediactrl.Play();
31 }
32
33
34 }
35 }
Press F5 to get output
I hope this article was useful. Thanks for reading. Happy coding.
I found this blog post very useful, thank for sharing. I was trying to develop silverlight game application which can run on iPhone, do you have any example application.
Thanks for step by step making me understand and work with mobile applications.