ListVideo
authorPAMPHILE Jonathan <pamphile@efrei.fr>
Wed, 23 Sep 2009 16:47:42 +0200
changeset 84 067f4a6c0cca
parent 83 841de52a9f83
child 85 3e8532a77c2e
child 87 68f4c0d7a7fc
ListVideo
src/FingersDance.Control.ListVideo/FingersDance.Control.ListVideo.csproj
src/FingersDance.Control.ListVideo/ListVideoItem.cs
src/FingersDance.Control.ListVideo/UserControlListVideo.xaml
src/FingersDance.Control.ListVideo/UserControlListVideo.xaml.cs
--- a/src/FingersDance.Control.ListVideo/FingersDance.Control.ListVideo.csproj	Wed Sep 23 12:08:58 2009 +0200
+++ b/src/FingersDance.Control.ListVideo/FingersDance.Control.ListVideo.csproj	Wed Sep 23 16:47:42 2009 +0200
@@ -69,6 +69,7 @@
     <Resource Include="Lake.jpg" />
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="ListVideoItem.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <EmbeddedResource Include="Properties\Resources.resx">
       <Generator>ResXFileCodeGenerator</Generator>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/FingersDance.Control.ListVideo/ListVideoItem.cs	Wed Sep 23 16:47:42 2009 +0200
@@ -0,0 +1,35 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace FingersDance.Control.ListVideo
+{
+    [Serializable]
+    public class ListVideoItem
+    {
+        string _Name = "";
+        string _Path = "";
+        string _Preview = "";
+
+        public string Name
+        {
+            get { return _Name; }
+            set { _Name = value; }
+        }
+
+        public string Path
+        {
+            get { return _Path; }
+            set { _Path = value; }
+        }
+
+        public string Preview
+        {
+            get { return _Preview; }
+            set { _Preview = value; }
+        }
+
+        public ListVideoItem() { }
+    }
+}
--- a/src/FingersDance.Control.ListVideo/UserControlListVideo.xaml	Wed Sep 23 12:08:58 2009 +0200
+++ b/src/FingersDance.Control.ListVideo/UserControlListVideo.xaml	Wed Sep 23 16:47:42 2009 +0200
@@ -6,18 +6,25 @@
 	mc:Ignorable="d"
 	x:Class="FingersDance.Control.ListVideo.UserControlListVideo"
 	x:Name="UserControl"
-	Width="404" Height="272.56" xmlns:Custom="http://schemas.microsoft.com/surface/2008" Background="{x:Null}">
+	Width="478" Height="288.56" xmlns:Custom="http://schemas.microsoft.com/surface/2008" Background="{x:Null}">
 
-	<Grid x:Name="LayoutRoot" Width="{Binding Path=ActualWidth, ElementName=UserControl, Mode=Default}" Height="{Binding Path=ActualHeight, ElementName=UserControl, Mode=Default}">
-		<Custom:SurfaceListBox IsSynchronizedWithCurrentItem="True" Background="{x:Null}" ScrollViewer.VerticalScrollBarVisibility="Hidden" Width="{Binding Path=ActualWidth, ElementName=UserControl, Mode=Default}" Height="{Binding Path=ActualHeight, ElementName=UserControl, Mode=Default}" x:Name="ListBoxVideos">
-			<StackPanel Width="404" Height="272.56" Orientation="Horizontal" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" x:Name="StackPanel">
-				<Custom:SurfaceListBoxItem Width="200" Height="200" Background="#00FFFFFF" x:Name="ItemVideo1" ContactTapGesture="ItemVideo1_ContactTapGesture">
-					<Image Width="200" Height="200" Source="Butterfly.jpg"/>
-				</Custom:SurfaceListBoxItem>
-				<Custom:SurfaceListBoxItem Width="200" Height="200" x:Name="ItemVideo2">
-					<Image Width="200" Height="200" Source="Lake.jpg"/>
-				</Custom:SurfaceListBoxItem>
+	<Grid x:Name="LayoutRoot">
+		<Custom:SurfaceListBox IsSynchronizedWithCurrentItem="True" Background="{x:Null}" ScrollViewer.VerticalScrollBarVisibility="Hidden" x:Name="ListBoxVideos" VerticalAlignment="Top" Height="167.56" Margin="8,0">
+			<StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" x:Name="stackPanel" RenderTransformOrigin="0.5,0.5">
+				<StackPanel.RenderTransform>
+					<TransformGroup>
+						<ScaleTransform/>
+						<SkewTransform AngleY="-0.182"/>
+						<RotateTransform/>
+						<TranslateTransform Y="-0.497"/>
+					</TransformGroup>
+				</StackPanel.RenderTransform>
 			</StackPanel>
 		</Custom:SurfaceListBox>
+		<Custom:SurfaceTextBox x:Name="PathImporter" Margin="152,0,104.427,71.81" VerticalAlignment="Bottom" TextWrapping="Wrap" Height="20" d:LayoutOverrides="VerticalAlignment"/>
+		<Label x:Name="LabelImporter" HorizontalAlignment="Left" Margin="14,0,0,67.81" VerticalAlignment="Bottom" Width="122" Height="28" Content="Importer une vidéo :" d:LayoutOverrides="VerticalAlignment"/>
+		<Custom:SurfaceButton x:Name="ButtonImporter" HorizontalAlignment="Right" Margin="0,0,14,66" VerticalAlignment="Bottom" Width="76" Height="17.96" Content="Importer" d:LayoutOverrides="VerticalAlignment" ContactDown="ButtonImporter_ContactDown" Click="ButtonImporter_Click"/>
+		<Custom:SurfaceButton HorizontalAlignment="Right" Margin="0,0,104.427,8" VerticalAlignment="Bottom" Width="76" Height="21" Content="Ok"/>
+		<Custom:SurfaceButton HorizontalAlignment="Right" Margin="0,0,14,8" VerticalAlignment="Bottom" Width="76" Height="30" Content="Annuler"/>
 	</Grid>
 </UserControl>
\ No newline at end of file
--- a/src/FingersDance.Control.ListVideo/UserControlListVideo.xaml.cs	Wed Sep 23 12:08:58 2009 +0200
+++ b/src/FingersDance.Control.ListVideo/UserControlListVideo.xaml.cs	Wed Sep 23 16:47:42 2009 +0200
@@ -7,21 +7,28 @@
 using System.Windows.Media;
 using System.Windows.Media.Animation;
 using System.Windows.Navigation;
+using Microsoft.Surface;
+using Microsoft.Surface.Presentation;
+using Microsoft.Surface.Presentation.Controls;
+using System.Collections.Generic;
+using System.Windows.Media.Imaging;
 
 namespace FingersDance.Control.ListVideo
 {
-	public partial class UserControlListVideo
-	{
+    public partial class UserControlListVideo
+    {
         //Creation d'un Event pour Chaque Item Video
         public event EventHandler EH_ItemVideo1_ContactDown;
         public event EventHandler EH_ItemVideo2_ContactDown;
 
-		public UserControlListVideo()
-		{
-			this.InitializeComponent();
+        List<string> _Videos = new List<string>();
 
-			// Insert code required on object creation below this point.
-		}
+        public UserControlListVideo()
+        {
+            this.InitializeComponent();
+
+            // Insert code required on object creation below this point.
+        }
 
         private void ItemVideo1_ContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e)
         {
@@ -41,5 +48,77 @@
             if (EH_ItemVideo1_ContactDown != null)
                 EH_ItemVideo1_ContactDown(this, new EventArgs());
         }
-	}
+
+        private void ButtonImporter_ContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e)
+        {
+            AddVideoToList();
+        }
+
+        private void ButtonImporter_Click(object sender, System.Windows.RoutedEventArgs e)
+        {
+            AddVideoToList();
+        }
+
+        private void AddVideoToList()
+        {
+            try
+            {
+                string[] Files = new string[1];
+                if (System.IO.Directory.Exists(PathImporter.Text))
+                    Files = System.IO.Directory.GetFiles(PathImporter.Text);
+                else
+                    if (System.IO.File.Exists(PathImporter.Text))
+                        Files[0] = PathImporter.Text;
+                if (Files != null)
+                    foreach (string elt in Files)
+                        if (elt.ToLower().EndsWith(".wmv")) // .....
+                            try
+                            {
+                                Image item = getFirstPreview(elt);
+                                if (item != null)
+                                {
+                                    SurfaceListBoxItem Contener = new SurfaceListBoxItem();
+                                    Contener.Content = item;
+                                    Contener.ContactHoldGesture += new ContactEventHandler(Contener_ContactHoldGesture);
+                                    stackPanel.Children.Add(Contener);
+
+                                    _Videos.Add(elt);
+                                }
+                            }
+                            catch (Exception ex) { }
+            }
+            catch (Exception) { }
+        }
+
+        void Contener_ContactHoldGesture(object sender, ContactEventArgs e)
+        {
+            SurfaceContextMenu Menu = new SurfaceContextMenu();
+            Menu.Items.Add("Supprimer");
+            ((SurfaceListBoxItem)sender).ContextMenu = Menu;
+
+        }
+
+        Image getFirstPreview(string path)
+        {
+            MediaPlayer _player = new MediaPlayer();
+            _player.Open(new Uri(path));
+            _player.Play();
+            _player.Position = new TimeSpan(0, 0, 5);
+            System.Threading.Thread.Sleep(800);
+            RenderTargetBitmap target = new RenderTargetBitmap(100, 100, 1 / 100, 1 / 100, PixelFormats.Pbgra32);
+            DrawingVisual visual = new DrawingVisual();
+            DrawingContext context = visual.RenderOpen();
+            Rect frameRect = new Rect();
+            frameRect.Height = target.Height;
+            frameRect.Width = target.Width;
+            context.DrawVideo(_player, frameRect);
+            context.Close();
+            target.Render(visual);
+            Image _prev = new Image();
+            _prev.Source = BitmapFrame.Create(target).GetAsFrozen() as BitmapFrame;
+            _player.Stop();
+
+            return _prev;
+        }
+    }
 }
\ No newline at end of file