author | PAMPHILE Jonathan <pamphile@efrei.fr> |
Fri, 25 Sep 2009 02:56:57 +0200 | |
changeset 121 | 32611257e99f |
parent 119 | 7a370bfb4d77 |
child 122 | b489c2756a13 |
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 |
|
14 |
namespace FingersDance.Control.Player |
|
15 |
{ |
|
16 |
public partial class UserControlPlayer |
|
17 |
{ |
|
34 | 18 |
#region Variables |
19 |
private bool isPlaying = false; |
|
20 |
#endregion |
|
3 | 21 |
|
34 | 22 |
public event EventHandler PlayerOpened; |
3 | 23 |
|
119 | 24 |
public UserControlPlayer() |
25 |
{ |
|
26 |
this.InitializeComponent(); |
|
121
32611257e99f
Link PLayer - SessionInput
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
119
diff
changeset
|
27 |
MediaElementVideo.LoadedBehavior = MediaState.Manual; |
32611257e99f
Link PLayer - SessionInput
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
119
diff
changeset
|
28 |
MediaElementVideo.UnloadedBehavior = MediaState.Manual; |
119 | 29 |
} |
30 |
||
34 | 31 |
#region Properties |
32 |
public double TotalMilliseconds |
|
33 |
{ |
|
34 |
get |
|
35 |
{ |
|
36 |
return MediaElementVideo.NaturalDuration.TimeSpan.TotalMilliseconds; |
|
37 |
} |
|
38 |
} |
|
39 |
public MediaElement Player |
|
40 |
{ |
|
41 |
get |
|
42 |
{ |
|
43 |
return MediaElementVideo; |
|
44 |
} |
|
45 |
set |
|
46 |
{ |
|
47 |
MediaElementVideo= value; |
|
48 |
} |
|
49 |
} |
|
50 |
||
51 |
#endregion |
|
52 |
||
53 |
||
54 |
#region Methodes |
|
3 | 55 |
void initPlayer() |
121
32611257e99f
Link PLayer - SessionInput
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
119
diff
changeset
|
56 |
{/* |
3 | 57 |
//init player |
34 | 58 |
isPlaying = false; |
41 | 59 |
//Pour se diriger vers le Dossier ressources du projet et non le bin/ressources |
49 | 60 |
//DirectoryInfo info = Directory.GetParent(@"."); |
61 |
FileInfo assemblyPath = new FileInfo(Assembly.GetExecutingAssembly().Location); |
|
62 |
DirectoryInfo info = assemblyPath.Directory; |
|
77 | 63 |
MediaElementVideo.Source = new Uri(@"" + info.FullName.ToString() + "\\Resources\\Lake.wmv", UriKind.Relative); |
3 | 64 |
MediaElementVideo.LoadedBehavior = MediaState.Manual; |
34 | 65 |
MediaElementVideo.UnloadedBehavior = MediaState.Manual; |
121
32611257e99f
Link PLayer - SessionInput
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
119
diff
changeset
|
66 |
MediaElementVideo.ScrubbingEnabled= true;*/ |
3 | 67 |
} |
68 |
||
119 | 69 |
public void initPlayer(string path) |
70 |
{ |
|
71 |
//init player |
|
72 |
isPlaying = false; |
|
121
32611257e99f
Link PLayer - SessionInput
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
119
diff
changeset
|
73 |
MediaElementVideo.Source = new Uri(path); |
119 | 74 |
MediaElementVideo.ScrubbingEnabled = true; |
75 |
} |
|
76 |
||
34 | 77 |
public void playerPause() |
78 |
{ |
|
79 |
MediaElementVideo.Pause(); |
|
80 |
} |
|
81 |
public void playerPlay() |
|
82 |
{ |
|
83 |
MediaElementVideo.Play(); |
|
84 |
} |
|
85 |
public void playerStop() |
|
86 |
{ |
|
87 |
MediaElementVideo.Stop(); |
|
88 |
} |
|
89 |
|
|
90 |
#endregion |
|
91 |
||
3 | 92 |
private void ButtonPlayPause_ContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e) |
93 |
{ |
|
34 | 94 |
if (!isPlaying)//Play |
3 | 95 |
{ |
34 | 96 |
isPlaying = true; |
3 | 97 |
try |
98 |
{ |
|
99 |
MediaElementVideo.Play(); |
|
100 |
} |
|
101 |
catch (Exception ex) { } |
|
102 |
} |
|
103 |
else//Pause |
|
104 |
{ |
|
34 | 105 |
isPlaying = false; |
3 | 106 |
try |
107 |
{ |
|
108 |
MediaElementVideo.Pause(); |
|
109 |
} |
|
34 | 110 |
catch (Exception exx) { } |
3 | 111 |
} |
112 |
||
113 |
} |
|
114 |
||
115 |
private void ButtonPlayPause_Click(object sender, RoutedEventArgs e) |
|
116 |
{ |
|
34 | 117 |
if (!isPlaying)//Play |
3 | 118 |
{ |
34 | 119 |
isPlaying = true; |
3 | 120 |
try |
121 |
{ |
|
122 |
MediaElementVideo.Play(); |
|
123 |
} |
|
34 | 124 |
catch (Exception ex) { } |
125 |
||
3 | 126 |
} |
127 |
else//Pause |
|
128 |
{ |
|
34 | 129 |
isPlaying = false; |
3 | 130 |
try |
131 |
{ |
|
132 |
MediaElementVideo.Pause(); |
|
133 |
} |
|
34 | 134 |
catch (Exception exx) { } |
135 |
//ButtonPlayPause.Background = FindResource("[Skin_1]_Play_button_xaml") as Brush; |
|
136 |
} |
|
137 |
} |
|
138 |
||
139 |
private void ButtonFastForward_Click(object sender, RoutedEventArgs e) |
|
140 |
{ |
|
141 |
if (MediaElementVideo.SpeedRatio <= 3) |
|
142 |
MediaElementVideo.SpeedRatio += 1; |
|
143 |
} |
|
144 |
||
145 |
private void ButtonFastForward_ContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e) |
|
146 |
{ |
|
147 |
if (MediaElementVideo.SpeedRatio <= 3) |
|
148 |
MediaElementVideo.SpeedRatio += 1; |
|
149 |
} |
|
150 |
||
151 |
private void ButtonRewind_Click(object sender, RoutedEventArgs e) |
|
152 |
{ |
|
153 |
//TimeSpan ts = new TimeSpan(0, 0, 0, 0); |
|
154 |
if (MediaElementVideo.SpeedRatio > 1) |
|
155 |
{ |
|
156 |
MediaElementVideo.SpeedRatio -= 1; |
|
3 | 157 |
} |
34 | 158 |
else |
159 |
{ |
|
160 |
MediaElementVideo.Position = MediaElementVideo.Position.Add(new TimeSpan(0, 0, 0, -5)); |
|
161 |
} |
|
162 |
} |
|
163 |
||
164 |
private void ButtonRewind_ContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e) |
|
165 |
{ |
|
166 |
||
167 |
//TimeSpan ts = new TimeSpan(0, 0, 0,0); |
|
168 |
if (MediaElementVideo.SpeedRatio > 1) |
|
169 |
{ |
|
170 |
MediaElementVideo.SpeedRatio -= 1; |
|
171 |
} |
|
172 |
else |
|
173 |
{ |
|
174 |
MediaElementVideo.Position = MediaElementVideo.Position.Add(new TimeSpan(0, 0, 0, -5)); |
|
175 |
} |
|
176 |
} |
|
177 |
||
178 |
private void MediaElementVideo_MediaOpened(object sender, RoutedEventArgs e) |
|
179 |
{ |
|
180 |
OnPlayerOpened(); |
|
181 |
} |
|
182 |
protected virtual void OnPlayerOpened() |
|
183 |
{ |
|
184 |
if(PlayerOpened!=null) |
|
185 |
PlayerOpened(this, new EventArgs()); |
|
3 | 186 |
} |
187 |
} |
|
188 |
} |