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