author | PAMPHILE Jonathan <pamphile@efrei.fr> |
Fri, 25 Sep 2009 03:38:22 +0200 | |
changeset 123 | 8af72b302e0a |
parent 117 | c1222ecbf1b1 |
child 143 | 9f157d9c725b |
permissions | -rw-r--r-- |
72
f1ca0958c992
Travail sur le control List Video et comunication entre ListVideo et FingersDance
sarias
parents:
diff
changeset
|
1 |
using System; |
f1ca0958c992
Travail sur le control List Video et comunication entre ListVideo et FingersDance
sarias
parents:
diff
changeset
|
2 |
using System.IO; |
f1ca0958c992
Travail sur le control List Video et comunication entre ListVideo et FingersDance
sarias
parents:
diff
changeset
|
3 |
using System.Net; |
f1ca0958c992
Travail sur le control List Video et comunication entre ListVideo et FingersDance
sarias
parents:
diff
changeset
|
4 |
using System.Windows; |
f1ca0958c992
Travail sur le control List Video et comunication entre ListVideo et FingersDance
sarias
parents:
diff
changeset
|
5 |
using System.Windows.Controls; |
f1ca0958c992
Travail sur le control List Video et comunication entre ListVideo et FingersDance
sarias
parents:
diff
changeset
|
6 |
using System.Windows.Data; |
f1ca0958c992
Travail sur le control List Video et comunication entre ListVideo et FingersDance
sarias
parents:
diff
changeset
|
7 |
using System.Windows.Media; |
f1ca0958c992
Travail sur le control List Video et comunication entre ListVideo et FingersDance
sarias
parents:
diff
changeset
|
8 |
using System.Windows.Media.Animation; |
f1ca0958c992
Travail sur le control List Video et comunication entre ListVideo et FingersDance
sarias
parents:
diff
changeset
|
9 |
using System.Windows.Navigation; |
84 | 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; |
|
95 | 15 |
using System.Xml.Serialization; |
16 |
using System.Reflection; |
|
72
f1ca0958c992
Travail sur le control List Video et comunication entre ListVideo et FingersDance
sarias
parents:
diff
changeset
|
17 |
|
f1ca0958c992
Travail sur le control List Video et comunication entre ListVideo et FingersDance
sarias
parents:
diff
changeset
|
18 |
namespace FingersDance.Control.ListVideo |
f1ca0958c992
Travail sur le control List Video et comunication entre ListVideo et FingersDance
sarias
parents:
diff
changeset
|
19 |
{ |
84 | 20 |
public partial class UserControlListVideo |
21 |
{ |
|
77 | 22 |
//Creation d'un Event pour Chaque Item Video |
72
f1ca0958c992
Travail sur le control List Video et comunication entre ListVideo et FingersDance
sarias
parents:
diff
changeset
|
23 |
public event EventHandler EH_ItemVideo1_ContactDown; |
f1ca0958c992
Travail sur le control List Video et comunication entre ListVideo et FingersDance
sarias
parents:
diff
changeset
|
24 |
|
95 | 25 |
public string path = ""; |
123
8af72b302e0a
Singletton ListVideos
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
117
diff
changeset
|
26 |
|
84 | 27 |
public UserControlListVideo() |
28 |
{ |
|
29 |
this.InitializeComponent(); |
|
95 | 30 |
UpdateList(); |
84 | 31 |
|
32 |
// Insert code required on object creation below this point. |
|
33 |
} |
|
72
f1ca0958c992
Travail sur le control List Video et comunication entre ListVideo et FingersDance
sarias
parents:
diff
changeset
|
34 |
|
95 | 35 |
//Event appelé lors de la selection d'un Item dans la Video List |
36 |
private void ItemVideo_ContactTapGesture(object sender, Microsoft.Surface.Presentation.ContactEventArgs e) |
|
72
f1ca0958c992
Travail sur le control List Video et comunication entre ListVideo et FingersDance
sarias
parents:
diff
changeset
|
37 |
{ |
95 | 38 |
path = ((CustomListBoxItem)sender).Path; |
72
f1ca0958c992
Travail sur le control List Video et comunication entre ListVideo et FingersDance
sarias
parents:
diff
changeset
|
39 |
if (EH_ItemVideo1_ContactDown != null) |
f1ca0958c992
Travail sur le control List Video et comunication entre ListVideo et FingersDance
sarias
parents:
diff
changeset
|
40 |
EH_ItemVideo1_ContactDown(this, new EventArgs()); |
95 | 41 |
|
72
f1ca0958c992
Travail sur le control List Video et comunication entre ListVideo et FingersDance
sarias
parents:
diff
changeset
|
42 |
} |
f1ca0958c992
Travail sur le control List Video et comunication entre ListVideo et FingersDance
sarias
parents:
diff
changeset
|
43 |
|
95 | 44 |
private void ItemVideo_Click(object sender, System.Windows.RoutedEventArgs e) |
72
f1ca0958c992
Travail sur le control List Video et comunication entre ListVideo et FingersDance
sarias
parents:
diff
changeset
|
45 |
{ |
95 | 46 |
path = ((CustomListBoxItem)sender).Path; |
72
f1ca0958c992
Travail sur le control List Video et comunication entre ListVideo et FingersDance
sarias
parents:
diff
changeset
|
47 |
if (EH_ItemVideo1_ContactDown != null) |
f1ca0958c992
Travail sur le control List Video et comunication entre ListVideo et FingersDance
sarias
parents:
diff
changeset
|
48 |
EH_ItemVideo1_ContactDown(this, new EventArgs()); |
95 | 49 |
|
72
f1ca0958c992
Travail sur le control List Video et comunication entre ListVideo et FingersDance
sarias
parents:
diff
changeset
|
50 |
} |
84 | 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 |
{ |
|
123
8af72b302e0a
Singletton ListVideos
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
117
diff
changeset
|
66 |
Dictionary<string, ListVideoItem> _Videos = (new ListVideo()).GetVideos(); |
84 | 67 |
string[] Files = new string[1]; |
68 |
if (System.IO.Directory.Exists(PathImporter.Text)) |
|
69 |
Files = System.IO.Directory.GetFiles(PathImporter.Text); |
|
70 |
else |
|
71 |
if (System.IO.File.Exists(PathImporter.Text)) |
|
72 |
Files[0] = PathImporter.Text; |
|
73 |
if (Files != null) |
|
95 | 74 |
{ |
84 | 75 |
foreach (string elt in Files) |
76 |
if (elt.ToLower().EndsWith(".wmv")) // ..... |
|
77 |
try |
|
78 |
{ |
|
95 | 79 |
ListVideoItem newItem = new ListVideoItem(); |
84 | 80 |
Image item = getFirstPreview(elt); |
95 | 81 |
if (item != null && !_Videos.ContainsKey(elt)) |
84 | 82 |
{ |
95 | 83 |
newItem.Name = elt.Split('\\')[elt.Split('\\').Length - 1].Split('.')[0]; |
84 |
newItem.Path = elt; |
|
85 |
newItem.Preview = elt.Replace(".wmv", ".jpg"); |
|
86 |
_Videos.Add(newItem.Path, newItem); |
|
84 | 87 |
} |
88 |
} |
|
89 |
catch (Exception ex) { } |
|
95 | 90 |
UpdateList(); |
91 |
SaveList(); |
|
92 |
} |
|
84 | 93 |
} |
94 |
catch (Exception) { } |
|
95 |
} |
|
96 |
||
97 |
Image getFirstPreview(string path) |
|
98 |
{ |
|
99 |
MediaPlayer _player = new MediaPlayer(); |
|
100 |
_player.Open(new Uri(path)); |
|
101 |
_player.Play(); |
|
102 |
_player.Position = new TimeSpan(0, 0, 5); |
|
103 |
System.Threading.Thread.Sleep(800); |
|
104 |
RenderTargetBitmap target = new RenderTargetBitmap(100, 100, 1 / 100, 1 / 100, PixelFormats.Pbgra32); |
|
105 |
DrawingVisual visual = new DrawingVisual(); |
|
106 |
DrawingContext context = visual.RenderOpen(); |
|
107 |
Rect frameRect = new Rect(); |
|
108 |
frameRect.Height = target.Height; |
|
109 |
frameRect.Width = target.Width; |
|
110 |
context.DrawVideo(_player, frameRect); |
|
111 |
context.Close(); |
|
112 |
target.Render(visual); |
|
113 |
Image _prev = new Image(); |
|
114 |
_prev.Source = BitmapFrame.Create(target).GetAsFrozen() as BitmapFrame; |
|
115 |
_player.Stop(); |
|
116 |
||
117 |
return _prev; |
|
118 |
} |
|
95 | 119 |
|
120 |
private void RefreshButton_ContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e) |
|
121 |
{ |
|
122 |
UpdateList(); |
|
123 |
} |
|
124 |
||
125 |
private void RefreshButton_Click(object sender, System.Windows.RoutedEventArgs e) |
|
126 |
{ |
|
127 |
UpdateList(); |
|
128 |
} |
|
129 |
||
123
8af72b302e0a
Singletton ListVideos
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
117
diff
changeset
|
130 |
|
95 | 131 |
|
132 |
void SaveList() |
|
133 |
{ |
|
123
8af72b302e0a
Singletton ListVideos
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
117
diff
changeset
|
134 |
Dictionary<string, ListVideoItem> _Videos = (new ListVideo()).GetVideos(); |
95 | 135 |
StreamWriter writter = null; |
136 |
FileInfo assemblyPath = new FileInfo(Assembly.GetExecutingAssembly().Location); |
|
137 |
DirectoryInfo info = assemblyPath.Directory; |
|
138 |
try |
|
139 |
{ |
|
140 |
writter = new StreamWriter(info.FullName.ToString() + "\\Resources\\videos.xml"); |
|
141 |
XmlSerializer serializer = new XmlSerializer(typeof(List<ListVideoItem>)); |
|
142 |
List<ListVideoItem> temp = new List<ListVideoItem>(); |
|
143 |
foreach (KeyValuePair<string, ListVideoItem> elt in _Videos) |
|
144 |
temp.Add(elt.Value); |
|
145 |
serializer.Serialize(writter, temp); |
|
146 |
writter.Close(); |
|
147 |
} |
|
148 |
catch (Exception e) |
|
149 |
{ |
|
150 |
if (writter != null) |
|
151 |
writter.Close(); |
|
152 |
} |
|
153 |
} |
|
154 |
||
155 |
void UpdateList() |
|
156 |
{ |
|
123
8af72b302e0a
Singletton ListVideos
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
117
diff
changeset
|
157 |
Dictionary<string, ListVideoItem> _Videos = (new ListVideo()).GetVideos(); |
95 | 158 |
stackPanel.Children.Clear(); |
159 |
foreach (KeyValuePair<string, ListVideoItem> elt in _Videos) |
|
160 |
{ |
|
161 |
try |
|
162 |
{ |
|
163 |
if (!elt.Value.Preview.Equals("")) |
|
164 |
{ |
|
165 |
MediaElement item = new MediaElement(); |
|
166 |
item.Source = new Uri(elt.Value.Preview); |
|
167 |
item.Width = 100; |
|
168 |
item.Height = 100; |
|
169 |
CustomListBoxItem Contener = new CustomListBoxItem(); |
|
170 |
Contener.Content = item; |
|
171 |
Contener.Path = elt.Value.Path; |
|
172 |
Contener.Name = elt.Value.Name; |
|
173 |
Contener.ContactTapGesture += ItemVideo_ContactTapGesture; |
|
174 |
stackPanel.Children.Add(Contener); |
|
175 |
} |
|
176 |
} |
|
177 |
catch (Exception e) |
|
178 |
{ } |
|
179 |
} |
|
180 |
} |
|
117 | 181 |
|
182 |
private void SurfaceRadioButton_ContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e) |
|
183 |
{ |
|
184 |
if (Import_video_Container.Visibility == Visibility.Collapsed) |
|
185 |
{ |
|
186 |
Import_video_Container.Visibility = Visibility.Visible; |
|
187 |
} |
|
188 |
||
189 |
else if (Import_video_Container.Visibility == Visibility.Visible) |
|
190 |
{ |
|
191 |
Import_video_Container.Visibility = Visibility.Collapsed; |
|
192 |
} |
|
193 |
// TODO: Add event handler implementation here. |
|
194 |
} |
|
195 |
||
196 |
private void SurfaceRadioButton_Click(object sender, System.Windows.RoutedEventArgs e) |
|
197 |
{ |
|
198 |
if (Import_video_Container.Visibility == Visibility.Collapsed) |
|
199 |
{ |
|
200 |
Import_video_Container.Visibility = Visibility.Visible; |
|
201 |
} |
|
202 |
||
203 |
else if (Import_video_Container.Visibility == Visibility.Visible) |
|
204 |
{ |
|
205 |
Import_video_Container.Visibility = Visibility.Collapsed; |
|
206 |
} |
|
207 |
// TODO: Add event handler implementation here. |
|
208 |
} |
|
84 | 209 |
} |
72
f1ca0958c992
Travail sur le control List Video et comunication entre ListVideo et FingersDance
sarias
parents:
diff
changeset
|
210 |
} |