Select to view content in your preferred language

How do I import an Video without compiling it in the xap?

1157
2
08-09-2010 04:52 AM
jonataspovoas
Regular Contributor
Hi,

I made this simplified application to demostrate my code.

MainPage
<UserControl x:Class="MapAndVideo.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:esri="http://schemas.esri.com/arcgis/client/2009"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="600" 
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
    xmlns:userControls="clr-namespace:ESRI.ArcGIS.SilverlightMapApp"
    xmlns:actions="clr-namespace:ESRI.ArcGIS.SilverlightMapApp.Actions">
    <Grid x:Name="LayoutRoot" Background="{StaticResource BaseColor}">
        <Grid.RowDefinitions>
            <RowDefinition Height="30" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        
        <!--Menu bar-->
        <Grid Grid.Row="0" x:Name="TopMenuGrid" Background="{StaticResource BaseColor}">
            <Rectangle x:Name="BackgroundGradient" Opacity=".5" Fill="{StaticResource ReflectionGradient}" />
            <Button x:Name="btnOpen" Content="Video" Width="60" ToolTipService.ToolTip="Click to show a help video"/>
        </Grid>

        <!-- Body of the Application -->
        <Grid Grid.Row="1">
            <!-- Map View -->
            <esri:Map x:Name="Map" Background="{StaticResource BaseColor}" >
                <esri:ArcGISTiledMapServiceLayer ID="BaseLayer" 
            Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer" />
            </esri:Map>
            <!-- Scale Bar -->
            <userControls:ScaleBar x:Name="scaleBar" Opacity=".5" Map="{Binding ElementName=Map}" 
                       MapUnit="DecimalDegrees" Width="200" Fill="White" Margin="5,0,10,0" 
                                   IsHitTestVisible="False" HorizontalAlignment="Left" VerticalAlignment="Bottom" />
        </Grid>
    </Grid>
</UserControl>

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 ESRI.ArcGIS.Client;

namespace MapAndVideo
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            btnOpen.Click += BtnOpen_Click;
        }

        private void BtnOpen_Click(object sender, EventArgs e)
        {
            ChildWindow1 chdWindow = new ChildWindow1();
            chdWindow.Show();
        }
    }
}

ChildWindow1
<controls:ChildWindow 
    x:Class="MapAndVideo.ChildWindow1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
    Width="500" Height="423" 
    Title="Video - Click on the video to play" Background="{Binding Source={StaticResource BaseColor}}" BorderBrush="{Binding Source={StaticResource BaseColor}}" Foreground="{Binding Source={StaticResource BaseColor}}">
    
    <Grid x:Name="LayoutRoot" Margin="2">
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="23" />
        </Grid.RowDefinitions>

        <Grid Grid.Row="0">
            <MediaElement x:Name="video" Stretch="UniformToFill"/>
        </Grid>

        <StackPanel Grid.Row="1" Height="23">
            <Button x:Name="btnOK" Content="Close" Click="OKButton_Click" Width="75"  HorizontalAlignment="Right" ToolTipService.ToolTip="Click to Close the window"/>
        </StackPanel>
    </Grid>
</controls:ChildWindow>

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;

namespace MapAndVideo
{
    public partial class ChildWindow1 : ChildWindow
    {
        Boolean isPlaying = false;
        
        public ChildWindow1()
        {
            InitializeComponent();
            
            video.AutoPlay = false;
            video.Source = new Uri("video/Silverlight.wmv", UriKind.RelativeOrAbsolute);
            
            btnOK.Click += OKButton_Click;
            video.MouseLeftButtonDown += Video_MouseLeftButtonDown;
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
        }

        private void Video_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            isPlaying = !isPlaying;
            if (isPlaying) video.Play();
            else video.Pause();
        }
    }
}


In it, i have a button that calls an childWindow to show a video.

The problem is that the video is big (like 40Mb+) and if i put it as a Resource, when i complie the project it goes inside the xap, that grows to 40mbs.

since the idea of the video is to make it a help tool, not all users are gonna use it, but the all have to download the 40mbs of the video because it is inside the xap. is there any way to export the video outside the xap (as an folder, or anything like that)?
0 Kudos
2 Replies
AliMirzabeigi
Emerging Contributor
You should store your video files in your web server then set the Source of your MediaElement. Please take a look at ESRI interactive SDK samples at http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#VideoFills to get the whole idea.
0 Kudos
PaulLeedham
Deactivated User
We have 100s of Gbs of video that we display through our SewerTV viewer (http://gis.hudson.oh.us/SewerTV/) and we use the method suggested by ali.  Create a virtual directory on your server, apply the appropriate permissions and add your videos in here.  Another suggestion would be to convert your video to mp4 format.  This is usually considerably smaller than wmv format so the video will download much quicker to the client.

Thanks,

Paul Leedham
City of Hudson
http://gis.hudson.oh.us/
0 Kudos