author | cavaliet |
Tue, 06 Oct 2009 14:02:09 +0200 | |
changeset 134 | f5108a598aa7 |
parent 122 | b489c2756a13 |
child 135 | 84b3bf5ee3d2 |
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; |
3 | 13 |
|
134
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
14 |
using Microsoft.Surface.Presentation; |
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
15 |
using FingersDance.Views; |
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
16 |
using FingersDance.ViewModels; |
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
17 |
|
3 | 18 |
namespace FingersDance.Control.Player |
19 |
{ |
|
20 |
public partial class UserControlPlayer |
|
21 |
{ |
|
34 | 22 |
#region Variables |
23 |
private bool isPlaying = false; |
|
24 |
#endregion |
|
3 | 25 |
|
34 | 26 |
public event EventHandler PlayerOpened; |
3 | 27 |
|
119 | 28 |
public UserControlPlayer() |
29 |
{ |
|
30 |
this.InitializeComponent(); |
|
121
32611257e99f
Link PLayer - SessionInput
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
119
diff
changeset
|
31 |
MediaElementVideo.LoadedBehavior = MediaState.Manual; |
32611257e99f
Link PLayer - SessionInput
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
119
diff
changeset
|
32 |
MediaElementVideo.UnloadedBehavior = MediaState.Manual; |
119 | 33 |
} |
34 |
||
34 | 35 |
#region Properties |
36 |
public double TotalMilliseconds |
|
37 |
{ |
|
38 |
get |
|
39 |
{ |
|
40 |
return MediaElementVideo.NaturalDuration.TimeSpan.TotalMilliseconds; |
|
41 |
} |
|
42 |
} |
|
43 |
public MediaElement Player |
|
44 |
{ |
|
45 |
get |
|
46 |
{ |
|
47 |
return MediaElementVideo; |
|
48 |
} |
|
49 |
set |
|
50 |
{ |
|
51 |
MediaElementVideo= value; |
|
52 |
} |
|
53 |
} |
|
54 |
||
55 |
#endregion |
|
56 |
||
57 |
||
58 |
#region Methodes |
|
3 | 59 |
|
119 | 60 |
public void initPlayer(string path) |
61 |
{ |
|
62 |
//init player |
|
63 |
isPlaying = false; |
|
121
32611257e99f
Link PLayer - SessionInput
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
119
diff
changeset
|
64 |
MediaElementVideo.Source = new Uri(path); |
119 | 65 |
MediaElementVideo.ScrubbingEnabled = true; |
66 |
} |
|
67 |
||
34 | 68 |
public void playerPause() |
69 |
{ |
|
70 |
MediaElementVideo.Pause(); |
|
71 |
} |
|
72 |
public void playerPlay() |
|
73 |
{ |
|
74 |
MediaElementVideo.Play(); |
|
75 |
} |
|
76 |
public void playerStop() |
|
77 |
{ |
|
78 |
MediaElementVideo.Stop(); |
|
79 |
} |
|
80 |
|
|
81 |
#endregion |
|
82 |
||
3 | 83 |
private void ButtonPlayPause_ContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e) |
84 |
{ |
|
34 | 85 |
if (!isPlaying)//Play |
3 | 86 |
{ |
34 | 87 |
isPlaying = true; |
3 | 88 |
try |
89 |
{ |
|
90 |
MediaElementVideo.Play(); |
|
91 |
} |
|
92 |
catch (Exception ex) { } |
|
93 |
} |
|
94 |
else//Pause |
|
95 |
{ |
|
34 | 96 |
isPlaying = false; |
3 | 97 |
try |
98 |
{ |
|
99 |
MediaElementVideo.Pause(); |
|
100 |
} |
|
34 | 101 |
catch (Exception exx) { } |
3 | 102 |
} |
103 |
||
104 |
} |
|
105 |
||
106 |
private void ButtonPlayPause_Click(object sender, RoutedEventArgs e) |
|
107 |
{ |
|
34 | 108 |
if (!isPlaying)//Play |
3 | 109 |
{ |
34 | 110 |
isPlaying = true; |
3 | 111 |
try |
112 |
{ |
|
113 |
MediaElementVideo.Play(); |
|
114 |
} |
|
34 | 115 |
catch (Exception ex) { } |
116 |
||
3 | 117 |
} |
118 |
else//Pause |
|
119 |
{ |
|
34 | 120 |
isPlaying = false; |
3 | 121 |
try |
122 |
{ |
|
123 |
MediaElementVideo.Pause(); |
|
124 |
} |
|
34 | 125 |
catch (Exception exx) { } |
126 |
//ButtonPlayPause.Background = FindResource("[Skin_1]_Play_button_xaml") as Brush; |
|
127 |
} |
|
128 |
} |
|
129 |
||
130 |
private void ButtonFastForward_Click(object sender, RoutedEventArgs e) |
|
131 |
{ |
|
132 |
if (MediaElementVideo.SpeedRatio <= 3) |
|
133 |
MediaElementVideo.SpeedRatio += 1; |
|
134 |
} |
|
135 |
||
136 |
private void ButtonFastForward_ContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e) |
|
137 |
{ |
|
138 |
if (MediaElementVideo.SpeedRatio <= 3) |
|
139 |
MediaElementVideo.SpeedRatio += 1; |
|
140 |
} |
|
141 |
||
142 |
private void ButtonRewind_Click(object sender, RoutedEventArgs e) |
|
143 |
{ |
|
144 |
//TimeSpan ts = new TimeSpan(0, 0, 0, 0); |
|
145 |
if (MediaElementVideo.SpeedRatio > 1) |
|
146 |
{ |
|
147 |
MediaElementVideo.SpeedRatio -= 1; |
|
3 | 148 |
} |
34 | 149 |
else |
150 |
{ |
|
151 |
MediaElementVideo.Position = MediaElementVideo.Position.Add(new TimeSpan(0, 0, 0, -5)); |
|
152 |
} |
|
153 |
} |
|
154 |
||
155 |
private void ButtonRewind_ContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e) |
|
156 |
{ |
|
157 |
||
158 |
//TimeSpan ts = new TimeSpan(0, 0, 0,0); |
|
159 |
if (MediaElementVideo.SpeedRatio > 1) |
|
160 |
{ |
|
161 |
MediaElementVideo.SpeedRatio -= 1; |
|
162 |
} |
|
163 |
else |
|
164 |
{ |
|
165 |
MediaElementVideo.Position = MediaElementVideo.Position.Add(new TimeSpan(0, 0, 0, -5)); |
|
166 |
} |
|
167 |
} |
|
168 |
||
169 |
private void MediaElementVideo_MediaOpened(object sender, RoutedEventArgs e) |
|
170 |
{ |
|
171 |
OnPlayerOpened(); |
|
172 |
} |
|
173 |
protected virtual void OnPlayerOpened() |
|
174 |
{ |
|
175 |
if(PlayerOpened!=null) |
|
176 |
PlayerOpened(this, new EventArgs()); |
|
3 | 177 |
} |
134
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
178 |
|
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
179 |
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
|
180 |
{ |
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
181 |
//Console.WriteLine("Enter"); |
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
182 |
//Play_Pause_area.Opacity = 0.5; |
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
183 |
} |
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 |
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
|
186 |
{ |
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
187 |
//Console.WriteLine("Leave"); |
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
188 |
//Play_Pause_area.Opacity = 0; |
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
189 |
} |
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 |
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
|
192 |
{ |
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
193 |
//Console.WriteLine("Over"); |
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 |
|
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
196 |
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
|
197 |
{ |
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
198 |
//Console.WriteLine("Drop"); |
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
199 |
// 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
|
200 |
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
|
201 |
int nbSeconds = (int)annotationDataVM.TcBegin; |
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
202 |
int nbMilliSec = (int)((annotationDataVM.TcBegin * 1000)%1000); |
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
203 |
MediaElementVideo.Position = new TimeSpan(0, 0, 0, nbSeconds, nbMilliSec); |
f5108a598aa7
drag and drop places the video at the good timecode.
cavaliet
parents:
122
diff
changeset
|
204 |
} |
3 | 205 |
} |
206 |
} |