src/FingersDance.Control.ListVideo/UserControlListVideo.xaml.cs
changeset 84 067f4a6c0cca
parent 77 e95e916eb018
child 95 07972aa3f2e0
equal deleted inserted replaced
83:841de52a9f83 84:067f4a6c0cca
     5 using System.Windows.Controls;
     5 using System.Windows.Controls;
     6 using System.Windows.Data;
     6 using System.Windows.Data;
     7 using System.Windows.Media;
     7 using System.Windows.Media;
     8 using System.Windows.Media.Animation;
     8 using System.Windows.Media.Animation;
     9 using System.Windows.Navigation;
     9 using System.Windows.Navigation;
       
    10 using Microsoft.Surface;
       
    11 using Microsoft.Surface.Presentation;
       
    12 using Microsoft.Surface.Presentation.Controls;
       
    13 using System.Collections.Generic;
       
    14 using System.Windows.Media.Imaging;
    10 
    15 
    11 namespace FingersDance.Control.ListVideo
    16 namespace FingersDance.Control.ListVideo
    12 {
    17 {
    13 	public partial class UserControlListVideo
    18     public partial class UserControlListVideo
    14 	{
    19     {
    15         //Creation d'un Event pour Chaque Item Video
    20         //Creation d'un Event pour Chaque Item Video
    16         public event EventHandler EH_ItemVideo1_ContactDown;
    21         public event EventHandler EH_ItemVideo1_ContactDown;
    17         public event EventHandler EH_ItemVideo2_ContactDown;
    22         public event EventHandler EH_ItemVideo2_ContactDown;
    18 
    23 
    19 		public UserControlListVideo()
    24         List<string> _Videos = new List<string>();
    20 		{
       
    21 			this.InitializeComponent();
       
    22 
    25 
    23 			// Insert code required on object creation below this point.
    26         public UserControlListVideo()
    24 		}
    27         {
       
    28             this.InitializeComponent();
       
    29 
       
    30             // Insert code required on object creation below this point.
       
    31         }
    25 
    32 
    26         private void ItemVideo1_ContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e)
    33         private void ItemVideo1_ContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e)
    27         {
    34         {
    28             if (EH_ItemVideo1_ContactDown != null)
    35             if (EH_ItemVideo1_ContactDown != null)
    29                 EH_ItemVideo1_ContactDown(this, new EventArgs());
    36                 EH_ItemVideo1_ContactDown(this, new EventArgs());
    39         private void ItemVideo1_ContactTapGesture(object sender, Microsoft.Surface.Presentation.ContactEventArgs e)
    46         private void ItemVideo1_ContactTapGesture(object sender, Microsoft.Surface.Presentation.ContactEventArgs e)
    40         {
    47         {
    41             if (EH_ItemVideo1_ContactDown != null)
    48             if (EH_ItemVideo1_ContactDown != null)
    42                 EH_ItemVideo1_ContactDown(this, new EventArgs());
    49                 EH_ItemVideo1_ContactDown(this, new EventArgs());
    43         }
    50         }
    44 	}
    51 
       
    52         private void ButtonImporter_ContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e)
       
    53         {
       
    54             AddVideoToList();
       
    55         }
       
    56 
       
    57         private void ButtonImporter_Click(object sender, System.Windows.RoutedEventArgs e)
       
    58         {
       
    59             AddVideoToList();
       
    60         }
       
    61 
       
    62         private void AddVideoToList()
       
    63         {
       
    64             try
       
    65             {
       
    66                 string[] Files = new string[1];
       
    67                 if (System.IO.Directory.Exists(PathImporter.Text))
       
    68                     Files = System.IO.Directory.GetFiles(PathImporter.Text);
       
    69                 else
       
    70                     if (System.IO.File.Exists(PathImporter.Text))
       
    71                         Files[0] = PathImporter.Text;
       
    72                 if (Files != null)
       
    73                     foreach (string elt in Files)
       
    74                         if (elt.ToLower().EndsWith(".wmv")) // .....
       
    75                             try
       
    76                             {
       
    77                                 Image item = getFirstPreview(elt);
       
    78                                 if (item != null)
       
    79                                 {
       
    80                                     SurfaceListBoxItem Contener = new SurfaceListBoxItem();
       
    81                                     Contener.Content = item;
       
    82                                     Contener.ContactHoldGesture += new ContactEventHandler(Contener_ContactHoldGesture);
       
    83                                     stackPanel.Children.Add(Contener);
       
    84 
       
    85                                     _Videos.Add(elt);
       
    86                                 }
       
    87                             }
       
    88                             catch (Exception ex) { }
       
    89             }
       
    90             catch (Exception) { }
       
    91         }
       
    92 
       
    93         void Contener_ContactHoldGesture(object sender, ContactEventArgs e)
       
    94         {
       
    95             SurfaceContextMenu Menu = new SurfaceContextMenu();
       
    96             Menu.Items.Add("Supprimer");
       
    97             ((SurfaceListBoxItem)sender).ContextMenu = Menu;
       
    98 
       
    99         }
       
   100 
       
   101         Image getFirstPreview(string path)
       
   102         {
       
   103             MediaPlayer _player = new MediaPlayer();
       
   104             _player.Open(new Uri(path));
       
   105             _player.Play();
       
   106             _player.Position = new TimeSpan(0, 0, 5);
       
   107             System.Threading.Thread.Sleep(800);
       
   108             RenderTargetBitmap target = new RenderTargetBitmap(100, 100, 1 / 100, 1 / 100, PixelFormats.Pbgra32);
       
   109             DrawingVisual visual = new DrawingVisual();
       
   110             DrawingContext context = visual.RenderOpen();
       
   111             Rect frameRect = new Rect();
       
   112             frameRect.Height = target.Height;
       
   113             frameRect.Width = target.Width;
       
   114             context.DrawVideo(_player, frameRect);
       
   115             context.Close();
       
   116             target.Render(visual);
       
   117             Image _prev = new Image();
       
   118             _prev.Source = BitmapFrame.Create(target).GetAsFrozen() as BitmapFrame;
       
   119             _player.Stop();
       
   120 
       
   121             return _prev;
       
   122         }
       
   123     }
    45 }
   124 }