author | sarias |
Fri, 16 Oct 2009 21:37:16 +0200 | |
changeset 163 | d5148710e229 |
parent 162 | 0b9f989bcb37 |
child 165 | e78e40b9d761 |
permissions | -rw-r--r-- |
3 | 1 |
using System; |
2 |
using System.IO; |
|
3 |
using System.Net; |
|
4 |
using System.Windows; |
|
5 |
using System.Windows.Controls; |
|
6 |
using System.Windows.Data; |
|
7 |
using System.Windows.Media; |
|
8 |
using System.Windows.Media.Imaging; |
|
9 |
using System.Windows.Media.Animation; |
|
10 |
using System.Windows.Navigation; |
|
11 |
using System.ComponentModel; |
|
49 | 12 |
using System.Reflection; |
143 | 13 |
using System.Collections.Generic; |
14 |
||
15 |
using Microsoft.Surface.Presentation; |
|
16 |
using Microsoft.Surface.Presentation.Controls; |
|
156
e16c8c913c65
Color Factory et application des couleurs au pivot
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
146
diff
changeset
|
17 |
using FingersDance.Factory; |
143 | 18 |
using FingersDance.Actions; |
19 |
using FingersDance.Control.TimeLine; |
|
20 |
using FingersDance.Views; |
|
21 |
using FingersDance.ViewModels; |
|
3 | 22 |
|
23 |
namespace FingersDance.Control.Player |
|
24 |
{ |
|
25 |
public partial class UserControlPlayer |
|
26 |
{ |
|
34 | 27 |
#region Variables |
28 |
private bool isPlaying = false; |
|
29 |
#endregion |
|
3 | 30 |
|
34 | 31 |
public event EventHandler PlayerOpened; |
3 | 32 |
|
119 | 33 |
public UserControlPlayer() |
34 |
{ |
|
35 |
this.InitializeComponent(); |
|
121
32611257e99f
Link PLayer - SessionInput
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
119
diff
changeset
|
36 |
MediaElementVideo.LoadedBehavior = MediaState.Manual; |
32611257e99f
Link PLayer - SessionInput
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
119
diff
changeset
|
37 |
MediaElementVideo.UnloadedBehavior = MediaState.Manual; |
119 | 38 |
} |
39 |
||
34 | 40 |
#region Properties |
41 |
public double TotalMilliseconds |
|
42 |
{ |
|
43 |
get |
|
44 |
{ |
|
45 |
return MediaElementVideo.NaturalDuration.TimeSpan.TotalMilliseconds; |
|
46 |
} |
|
47 |
} |
|
48 |
public MediaElement Player |
|
49 |
{ |
|
50 |
get |
|
51 |
{ |
|
52 |
return MediaElementVideo; |
|
53 |
} |
|
54 |
set |
|
55 |
{ |
|
56 |
MediaElementVideo= value; |
|
57 |
} |
|
58 |
} |
|
59 |
||
60 |
#endregion |
|
61 |
||
62 |
||
63 |
#region Methodes |
|
3 | 64 |
|
119 | 65 |
public void initPlayer(string path) |
66 |
{ |
|
67 |
//init player |
|
68 |
isPlaying = false; |
|
121
32611257e99f
Link PLayer - SessionInput
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
119
diff
changeset
|
69 |
MediaElementVideo.Source = new Uri(path); |
119 | 70 |
MediaElementVideo.ScrubbingEnabled = true; |
71 |
} |
|
72 |
||
34 | 73 |
public void playerPause() |
74 |
{ |
|
75 |
MediaElementVideo.Pause(); |
|
76 |
} |
|
77 |
public void playerPlay() |
|
78 |
{ |
|
79 |
MediaElementVideo.Play(); |
|
80 |
} |
|
81 |
public void playerStop() |
|
82 |
{ |
|
83 |
MediaElementVideo.Stop(); |
|
84 |
} |
|
85 |
|
|
86 |
#endregion |
|
87 |
||
162
0b9f989bcb37
Display annotations in all opened UserPanels with the user's color
sarias
parents:
156
diff
changeset
|
88 |
#region Button Simple Player Actions |
3 | 89 |
private void ButtonPlayPause_ContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e) |
90 |
{ |
|
34 | 91 |
if (!isPlaying)//Play |
3 | 92 |
{ |
34 | 93 |
isPlaying = true; |
3 | 94 |
try |
95 |
{ |
|
96 |
MediaElementVideo.Play(); |
|
97 |
} |
|
98 |
catch (Exception ex) { } |
|
99 |
} |
|
100 |
else//Pause |
|
101 |
{ |
|
34 | 102 |
isPlaying = false; |
3 | 103 |
try |
104 |
{ |
|
105 |
MediaElementVideo.Pause(); |
|
106 |
} |
|
34 | 107 |
catch (Exception exx) { } |
3 | 108 |
} |
109 |
||
110 |
} |
|
111 |
||
112 |
private void ButtonPlayPause_Click(object sender, RoutedEventArgs e) |
|
113 |
{ |
|
34 | 114 |
if (!isPlaying)//Play |
3 | 115 |
{ |
34 | 116 |
isPlaying = true; |
3 | 117 |
try |
118 |
{ |
|
119 |
MediaElementVideo.Play(); |
|
120 |
} |
|
34 | 121 |
catch (Exception ex) { } |
122 |
||
3 | 123 |
} |
124 |
else//Pause |
|
125 |
{ |
|
34 | 126 |
isPlaying = false; |
3 | 127 |
try |
128 |
{ |
|
129 |
MediaElementVideo.Pause(); |
|
130 |
} |
|
34 | 131 |
catch (Exception exx) { } |
132 |
//ButtonPlayPause.Background = FindResource("[Skin_1]_Play_button_xaml") as Brush; |
|
133 |
} |
|
134 |
} |
|
135 |
||
136 |
private void ButtonFastForward_Click(object sender, RoutedEventArgs e) |
|
137 |
{ |
|
138 |
if (MediaElementVideo.SpeedRatio <= 3) |
|
139 |
MediaElementVideo.SpeedRatio += 1; |
|
140 |
} |
|
141 |
||
142 |
private void ButtonFastForward_ContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e) |
|
143 |
{ |
|
144 |
if (MediaElementVideo.SpeedRatio <= 3) |
|
145 |
MediaElementVideo.SpeedRatio += 1; |
|
146 |
} |
|
147 |
||
148 |
private void ButtonRewind_Click(object sender, RoutedEventArgs e) |
|
149 |
{ |
|
150 |
//TimeSpan ts = new TimeSpan(0, 0, 0, 0); |
|
151 |
if (MediaElementVideo.SpeedRatio > 1) |
|
152 |
{ |
|
153 |
MediaElementVideo.SpeedRatio -= 1; |
|
3 | 154 |
} |
34 | 155 |
else |
156 |
{ |
|
157 |
MediaElementVideo.Position = MediaElementVideo.Position.Add(new TimeSpan(0, 0, 0, -5)); |
|
158 |
} |
|
159 |
} |
|
160 |
||
161 |
private void ButtonRewind_ContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e) |
|
162 |
{ |
|
163 |
||
164 |
//TimeSpan ts = new TimeSpan(0, 0, 0,0); |
|
165 |
if (MediaElementVideo.SpeedRatio > 1) |
|
166 |
{ |
|
167 |
MediaElementVideo.SpeedRatio -= 1; |
|
168 |
} |
|
169 |
else |
|
170 |
{ |
|
171 |
MediaElementVideo.Position = MediaElementVideo.Position.Add(new TimeSpan(0, 0, 0, -5)); |
|
172 |
} |
|
173 |
} |
|
174 |
||
162
0b9f989bcb37
Display annotations in all opened UserPanels with the user's color
sarias
parents:
156
diff
changeset
|
175 |
#endregion |
0b9f989bcb37
Display annotations in all opened UserPanels with the user's color
sarias
parents:
156
diff
changeset
|
176 |
|
34 | 177 |
private void MediaElementVideo_MediaOpened(object sender, RoutedEventArgs e) |
178 |
{ |
|
179 |
OnPlayerOpened(); |
|
180 |
} |
|
181 |
protected virtual void OnPlayerOpened() |
|
182 |
{ |
|
183 |
if(PlayerOpened!=null) |
|
184 |
PlayerOpened(this, new EventArgs()); |
|
3 | 185 |
} |
143 | 186 |
|
187 |
private void Play_Pause_area_DragEnter(object sender, SurfaceDragDropEventArgs e) |
|
188 |
{ |
|
189 |
//Console.WriteLine("Enter"); |
|
190 |
||
191 |
// If the TimelineAnnotationView comes from a user control different from the current one, |
|
192 |
// it means that we want to add the annotation to the current list. |
|
193 |
// So we check if the dragged annotation can be dragged or if it will recover any existant annotation (in this case it will not be accepted) |
|
194 |
// e.Cursor.DragSource is the SurfaceListBox where the drag started from |
|
195 |
SurfaceListBox slb = (SurfaceListBox)e.Cursor.DragSource; |
|
196 |
// We get the instance of the UserControlSyncSource |
|
197 |
UserControl syncSrc = (UserControl)((Grid)((Grid)this.Parent).Parent).Parent; |
|
198 |
// and its UserControlTimeline |
|
199 |
UserControlTimeLine tl = (UserControlTimeLine)((Grid)((Grid)syncSrc.Content).Children[0]).Children[0]; |
|
200 |
if (((Grid)((UserControl)((Grid)slb.Parent).Parent).Parent).Parent != tl) |
|
201 |
{ |
|
202 |
// e.Cursor.Visual is the ContentControl, so its Content is the dragged TimelineAnnotationView |
|
203 |
AnnotationViewModel annotationDataVM = (AnnotationViewModel)((TimelineAnnotationView)((ContentControl)e.Cursor.Visual).Content).DataContext; |
|
204 |
Play_Pause_area.Background = tl.isAnnotationAccepted(annotationDataVM) ? new SolidColorBrush(Colors.Green) : new SolidColorBrush(Colors.Red); |
|
205 |
} |
|
206 |
else |
|
207 |
{ |
|
208 |
Play_Pause_area.Background = new SolidColorBrush(Colors.White); |
|
209 |
} |
|
210 |
Play_Pause_area.Opacity = 0.3; |
|
211 |
||
212 |
} |
|
213 |
||
214 |
private void Play_Pause_area_DragLeave(object sender, SurfaceDragDropEventArgs e) |
|
215 |
{ |
|
216 |
//Console.WriteLine("Leave"); |
|
217 |
Play_Pause_area.Opacity = 0; |
|
218 |
} |
|
219 |
||
220 |
private void Play_Pause_area_DragOver(object sender, SurfaceDragDropEventArgs e) |
|
221 |
{ |
|
222 |
//Console.WriteLine("Over"); |
|
223 |
} |
|
224 |
||
225 |
private void Play_Pause_area_Drop(object sender, SurfaceDragDropEventArgs e) |
|
226 |
{ |
|
227 |
//Console.WriteLine("Drop"); |
|
228 |
Play_Pause_area.Opacity = 0; |
|
229 |
// e.Cursor.Visual is the ContentControl, so its Content is the dragged TimelineAnnotationView |
|
230 |
AnnotationViewModel annotationDataVM = (AnnotationViewModel)((TimelineAnnotationView)((ContentControl)e.Cursor.Visual).Content).DataContext; |
|
231 |
int nbSeconds = (int)annotationDataVM.TcBegin; |
|
232 |
int nbMilliSec = (int)((annotationDataVM.TcBegin * 1000)%1000); |
|
233 |
MediaElementVideo.Position = new TimeSpan(0, 0, 0, nbSeconds, nbMilliSec); |
|
234 |
||
235 |
||
236 |
// If the TimelineAnnotationView comes from a user control different from the current one, |
|
237 |
// it means that we want to add the annotation to the current list. |
|
238 |
// So we generate the ActionAddAnnotation |
|
239 |
// e.Cursor.DragSource is the SurfaceListBox where the drag started from |
|
240 |
SurfaceListBox slb = (SurfaceListBox)e.Cursor.DragSource; |
|
241 |
// We get the instance of the UserControlSyncSource |
|
242 |
UserControl syncSrc = (UserControl)((Grid)((Grid)this.Parent).Parent).Parent; |
|
243 |
// and its UserControlTimeline |
|
244 |
UserControl tl = (UserControl)((Grid)((Grid)syncSrc.Content).Children[0]).Children[0]; |
|
245 |
if (((Grid)((UserControl)((Grid)slb.Parent).Parent).Parent).Parent != tl) |
|
246 |
{ |
|
247 |
// Now we build the action arguments : a list holding the timeline and the annotation view models |
|
248 |
List<Object> actionsArgs = new List<Object>(); |
|
249 |
actionsArgs.Add(tl); |
|
250 |
actionsArgs.Add(annotationDataVM); |
|
251 |
||
252 |
ActionGenerator ag = new ActionGenerator(); |
|
253 |
ActionBase ab = ag.GetAction("ActionAddAnnotation", actionsArgs); |
|
254 |
if (ab != null) |
|
255 |
ab.Execute(); |
|
256 |
} |
|
257 |
||
258 |
} |
|
162
0b9f989bcb37
Display annotations in all opened UserPanels with the user's color
sarias
parents:
156
diff
changeset
|
259 |
|
0b9f989bcb37
Display annotations in all opened UserPanels with the user's color
sarias
parents:
156
diff
changeset
|
260 |
//This function Sets a brush in a specific rectangle of the StackPanelAnnotation |
0b9f989bcb37
Display annotations in all opened UserPanels with the user's color
sarias
parents:
156
diff
changeset
|
261 |
public void displayStackPanelAnnotations(int id, Brush brushAnnotation) |
0b9f989bcb37
Display annotations in all opened UserPanels with the user's color
sarias
parents:
156
diff
changeset
|
262 |
{ |
163 | 263 |
Object o = null; |
162
0b9f989bcb37
Display annotations in all opened UserPanels with the user's color
sarias
parents:
156
diff
changeset
|
264 |
switch (id) |
0b9f989bcb37
Display annotations in all opened UserPanels with the user's color
sarias
parents:
156
diff
changeset
|
265 |
{ |
163 | 266 |
case 1: |
267 |
rect1.Fill = brushAnnotation; |
|
268 |
o = rect1.FindResource("Rect1Annotation"); |
|
269 |
rect1.BeginStoryboard((Storyboard)o); |
|
270 |
break; |
|
271 |
case 2: rect2.Fill = brushAnnotation; |
|
272 |
o = rect2.FindResource("Rect2Annotation"); |
|
273 |
rect2.BeginStoryboard((Storyboard)o); |
|
274 |
break; |
|
275 |
case 3: rect3.Fill = brushAnnotation; |
|
276 |
o = rect3.FindResource("Rect3Annotation"); |
|
277 |
rect3.BeginStoryboard((Storyboard)o); |
|
278 |
break; |
|
279 |
case 4: rect4.Fill = brushAnnotation; |
|
280 |
o = rect4.FindResource("Rect4Annotation"); |
|
281 |
rect4.BeginStoryboard((Storyboard)o); |
|
282 |
break; |
|
162
0b9f989bcb37
Display annotations in all opened UserPanels with the user's color
sarias
parents:
156
diff
changeset
|
283 |
default: break; |
0b9f989bcb37
Display annotations in all opened UserPanels with the user's color
sarias
parents:
156
diff
changeset
|
284 |
} |
0b9f989bcb37
Display annotations in all opened UserPanels with the user's color
sarias
parents:
156
diff
changeset
|
285 |
} |
3 | 286 |
} |
287 |
} |