author | cavaliet |
Wed, 07 Oct 2009 17:16:46 +0200 | |
changeset 135 | 84b3bf5ee3d2 |
parent 134 | f5108a598aa7 |
child 136 | 8b513df1b446 |
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; |
135
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
13 |
using System.Collections.Generic; |
3 | 14 |
|
134
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
15 |
using Microsoft.Surface.Presentation; |
135
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
16 |
using Microsoft.Surface.Presentation.Controls; |
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
17 |
using FingersDance.ActionFactory; |
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
18 |
using FingersDance.Actions; |
134
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
19 |
using FingersDance.Views; |
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
20 |
using FingersDance.ViewModels; |
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
21 |
|
3 | 22 |
namespace FingersDance.Control.Player |
23 |
{ |
|
24 |
public partial class UserControlPlayer |
|
25 |
{ |
|
34 | 26 |
#region Variables |
27 |
private bool isPlaying = false; |
|
28 |
#endregion |
|
3 | 29 |
|
34 | 30 |
public event EventHandler PlayerOpened; |
3 | 31 |
|
119 | 32 |
public UserControlPlayer() |
33 |
{ |
|
34 |
this.InitializeComponent(); |
|
121
32611257e99f
Link PLayer - SessionInput
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
119
diff
changeset
|
35 |
MediaElementVideo.LoadedBehavior = MediaState.Manual; |
32611257e99f
Link PLayer - SessionInput
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
119
diff
changeset
|
36 |
MediaElementVideo.UnloadedBehavior = MediaState.Manual; |
119 | 37 |
} |
38 |
||
34 | 39 |
#region Properties |
40 |
public double TotalMilliseconds |
|
41 |
{ |
|
42 |
get |
|
43 |
{ |
|
44 |
return MediaElementVideo.NaturalDuration.TimeSpan.TotalMilliseconds; |
|
45 |
} |
|
46 |
} |
|
47 |
public MediaElement Player |
|
48 |
{ |
|
49 |
get |
|
50 |
{ |
|
51 |
return MediaElementVideo; |
|
52 |
} |
|
53 |
set |
|
54 |
{ |
|
55 |
MediaElementVideo= value; |
|
56 |
} |
|
57 |
} |
|
58 |
||
59 |
#endregion |
|
60 |
||
61 |
||
62 |
#region Methodes |
|
3 | 63 |
|
119 | 64 |
public void initPlayer(string path) |
65 |
{ |
|
66 |
//init player |
|
67 |
isPlaying = false; |
|
121
32611257e99f
Link PLayer - SessionInput
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
119
diff
changeset
|
68 |
MediaElementVideo.Source = new Uri(path); |
119 | 69 |
MediaElementVideo.ScrubbingEnabled = true; |
70 |
} |
|
71 |
||
34 | 72 |
public void playerPause() |
73 |
{ |
|
74 |
MediaElementVideo.Pause(); |
|
75 |
} |
|
76 |
public void playerPlay() |
|
77 |
{ |
|
78 |
MediaElementVideo.Play(); |
|
79 |
} |
|
80 |
public void playerStop() |
|
81 |
{ |
|
82 |
MediaElementVideo.Stop(); |
|
83 |
} |
|
84 |
|
|
85 |
#endregion |
|
86 |
||
3 | 87 |
private void ButtonPlayPause_ContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e) |
88 |
{ |
|
34 | 89 |
if (!isPlaying)//Play |
3 | 90 |
{ |
34 | 91 |
isPlaying = true; |
3 | 92 |
try |
93 |
{ |
|
94 |
MediaElementVideo.Play(); |
|
95 |
} |
|
96 |
catch (Exception ex) { } |
|
97 |
} |
|
98 |
else//Pause |
|
99 |
{ |
|
34 | 100 |
isPlaying = false; |
3 | 101 |
try |
102 |
{ |
|
103 |
MediaElementVideo.Pause(); |
|
104 |
} |
|
34 | 105 |
catch (Exception exx) { } |
3 | 106 |
} |
107 |
||
108 |
} |
|
109 |
||
110 |
private void ButtonPlayPause_Click(object sender, RoutedEventArgs e) |
|
111 |
{ |
|
34 | 112 |
if (!isPlaying)//Play |
3 | 113 |
{ |
34 | 114 |
isPlaying = true; |
3 | 115 |
try |
116 |
{ |
|
117 |
MediaElementVideo.Play(); |
|
118 |
} |
|
34 | 119 |
catch (Exception ex) { } |
120 |
||
3 | 121 |
} |
122 |
else//Pause |
|
123 |
{ |
|
34 | 124 |
isPlaying = false; |
3 | 125 |
try |
126 |
{ |
|
127 |
MediaElementVideo.Pause(); |
|
128 |
} |
|
34 | 129 |
catch (Exception exx) { } |
130 |
//ButtonPlayPause.Background = FindResource("[Skin_1]_Play_button_xaml") as Brush; |
|
131 |
} |
|
132 |
} |
|
133 |
||
134 |
private void ButtonFastForward_Click(object sender, RoutedEventArgs e) |
|
135 |
{ |
|
136 |
if (MediaElementVideo.SpeedRatio <= 3) |
|
137 |
MediaElementVideo.SpeedRatio += 1; |
|
138 |
} |
|
139 |
||
140 |
private void ButtonFastForward_ContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e) |
|
141 |
{ |
|
142 |
if (MediaElementVideo.SpeedRatio <= 3) |
|
143 |
MediaElementVideo.SpeedRatio += 1; |
|
144 |
} |
|
145 |
||
146 |
private void ButtonRewind_Click(object sender, RoutedEventArgs e) |
|
147 |
{ |
|
148 |
//TimeSpan ts = new TimeSpan(0, 0, 0, 0); |
|
149 |
if (MediaElementVideo.SpeedRatio > 1) |
|
150 |
{ |
|
151 |
MediaElementVideo.SpeedRatio -= 1; |
|
3 | 152 |
} |
34 | 153 |
else |
154 |
{ |
|
155 |
MediaElementVideo.Position = MediaElementVideo.Position.Add(new TimeSpan(0, 0, 0, -5)); |
|
156 |
} |
|
157 |
} |
|
158 |
||
159 |
private void ButtonRewind_ContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e) |
|
160 |
{ |
|
161 |
||
162 |
//TimeSpan ts = new TimeSpan(0, 0, 0,0); |
|
163 |
if (MediaElementVideo.SpeedRatio > 1) |
|
164 |
{ |
|
165 |
MediaElementVideo.SpeedRatio -= 1; |
|
166 |
} |
|
167 |
else |
|
168 |
{ |
|
169 |
MediaElementVideo.Position = MediaElementVideo.Position.Add(new TimeSpan(0, 0, 0, -5)); |
|
170 |
} |
|
171 |
} |
|
172 |
||
173 |
private void MediaElementVideo_MediaOpened(object sender, RoutedEventArgs e) |
|
174 |
{ |
|
175 |
OnPlayerOpened(); |
|
176 |
} |
|
177 |
protected virtual void OnPlayerOpened() |
|
178 |
{ |
|
179 |
if(PlayerOpened!=null) |
|
180 |
PlayerOpened(this, new EventArgs()); |
|
3 | 181 |
} |
134
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
182 |
|
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
183 |
private void Play_Pause_area_DragEnter(object sender, SurfaceDragDropEventArgs e) |
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
184 |
{ |
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
185 |
//Console.WriteLine("Enter"); |
135
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
186 |
Play_Pause_area.Opacity = 0.5; |
134
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
187 |
} |
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
188 |
|
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
189 |
private void Play_Pause_area_DragLeave(object sender, SurfaceDragDropEventArgs e) |
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
190 |
{ |
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
191 |
//Console.WriteLine("Leave"); |
135
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
192 |
Play_Pause_area.Opacity = 0; |
134
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
193 |
} |
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
194 |
|
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
195 |
private void Play_Pause_area_DragOver(object sender, SurfaceDragDropEventArgs e) |
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
196 |
{ |
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
197 |
//Console.WriteLine("Over"); |
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
198 |
} |
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
199 |
|
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
200 |
private void Play_Pause_area_Drop(object sender, SurfaceDragDropEventArgs e) |
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
201 |
{ |
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
202 |
//Console.WriteLine("Drop"); |
135
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
203 |
Play_Pause_area.Opacity = 0; |
134
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
204 |
// e.Cursor.Visual is the ContentControl, so its Content is the dragged TimelineAnnotationView |
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
205 |
AnnotationViewModel annotationDataVM = (AnnotationViewModel)((TimelineAnnotationView)((ContentControl)e.Cursor.Visual).Content).DataContext; |
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
206 |
int nbSeconds = (int)annotationDataVM.TcBegin; |
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
207 |
int nbMilliSec = (int)((annotationDataVM.TcBegin * 1000)%1000); |
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
208 |
MediaElementVideo.Position = new TimeSpan(0, 0, 0, nbSeconds, nbMilliSec); |
135
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
209 |
|
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
210 |
|
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
211 |
// If the TimelineAnnotationView comes from a user control different from the current one, |
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
212 |
// it means that we want to add the annotation to the current list. |
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
213 |
// So we generate the ActionAddAnnotation |
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
214 |
// e.Cursor.DragSource is the SurfaceListBox where the drag started from |
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
215 |
SurfaceListBox slb = (SurfaceListBox)e.Cursor.DragSource; |
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
216 |
// We get the instance of the UserControlSyncSource |
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
217 |
UserControl syncSrc = (UserControl)((Grid)((Grid)this.Parent).Parent).Parent; |
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
218 |
// and its UserControlTimeline |
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
219 |
UserControl tl = (UserControl)((Grid)((Grid)syncSrc.Content).Children[0]).Children[0]; |
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
220 |
if (((Grid)((UserControl)((Grid)slb.Parent).Parent).Parent).Parent != tl) |
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
221 |
{ |
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
222 |
// Now we build the action arguments : a list holding the timeline and the annotation view models |
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
223 |
List<Object> actionsArgs = new List<Object>(); |
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
224 |
actionsArgs.Add(tl); |
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
225 |
actionsArgs.Add(annotationDataVM); |
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
226 |
|
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
227 |
ActionGenerator ag = new ActionGenerator(); |
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
228 |
ActionBase ab = ag.GetAction("ActionAddAnnotation", actionsArgs); |
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
229 |
if (ab != null) |
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
230 |
ab.Execute(); |
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
231 |
} |
84b3bf5ee3d2
First step of drag and drop annotation from a timeline to an other player
cavaliet
parents:
134
diff
changeset
|
232 |
|
134
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
233 |
} |
3 | 234 |
} |
235 |
} |