Thursday, January 3, 2013

Windows Phone playing video from a web resourcs

we can run a media file on player from a given link. we just need to follow few steps, for this purpose make a new project with the name PlayinMedia

1) Use the given below layout at MainPage.xaml



<phone:PhoneApplicationPage
    x:Class="PlayinMedia.MainPage"
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    shell:SystemTray.IsVisible="True" d:DesignHeight="768" d:DesignWidth="480">

 
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

   
        <!--ContentPanel - place additional content here-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <Button x:Name="launcher" Content="Click to Run Video" Height="100" Click="launcher_Click"/>
        </Grid>

     
    </Grid>

</phone:PhoneApplicationPage>



2) use the following code to MainPage.xaml.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;

using Microsoft.Phone.Tasks;

namespace PlayinMedia
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();

           
        }


        private void launcher_Click(object sender, RoutedEventArgs e)
        {
            MediaPlayerLauncher mediaPlayerLauncher = new MediaPlayerLauncher();
            //mediaPlayerLauncher.Media = new Uri(@"http://ecn.channel9.msdn.com/o9/ch9/7627/13997a12-79ff-4f95-9686-9de901877627/WP7JumpStartSession12_ch9.mp3", UriKind.Absolute);
            mediaPlayerLauncher.Media = new Uri(@"http://media.ch9.ms/ch9/2816/4362df50-9233-46d2-aa06-7e9887ba2816/Build2012Key02.wmv", UriKind.Absolute);
            mediaPlayerLauncher.Controls = MediaPlaybackControls.All;

            mediaPlayerLauncher.Location = MediaLocationType.Data;
            mediaPlayerLauncher.Show();
        }
    }
}

3) you can see the following screen shots for the output reference :)


No comments:

Post a Comment