author | PAMPHILE Jonathan <pamphile@efrei.fr> |
Fri, 25 Sep 2009 02:57:58 +0200 | |
changeset 122 | b489c2756a13 |
parent 121 | 32611257e99f |
child 134 | f5108a598aa7 |
child 143 | 9f157d9c725b |
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 |
|
119 | 56 |
public void initPlayer(string path) |
57 |
{ |
|
58 |
//init player |
|
59 |
isPlaying = false; |
|
121
32611257e99f
Link PLayer - SessionInput
PAMPHILE Jonathan <pamphile@efrei.fr>
parents:
119
diff
changeset
|
60 |
MediaElementVideo.Source = new Uri(path); |
119 | 61 |
MediaElementVideo.ScrubbingEnabled = true; |
62 |
} |
|
63 |
||
34 | 64 |
public void playerPause() |
65 |
{ |
|
66 |
MediaElementVideo.Pause(); |
|
67 |
} |
|
68 |
public void playerPlay() |
|
69 |
{ |
|
70 |
MediaElementVideo.Play(); |
|
71 |
} |
|
72 |
public void playerStop() |
|
73 |
{ |
|
74 |
MediaElementVideo.Stop(); |
|
75 |
} |
|
76 |
|
|
77 |
#endregion |
|
78 |
||
3 | 79 |
private void ButtonPlayPause_ContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e) |
80 |
{ |
|
34 | 81 |
if (!isPlaying)//Play |
3 | 82 |
{ |
34 | 83 |
isPlaying = true; |
3 | 84 |
try |
85 |
{ |
|
86 |
MediaElementVideo.Play(); |
|
87 |
} |
|
88 |
catch (Exception ex) { } |
|
89 |
} |
|
90 |
else//Pause |
|
91 |
{ |
|
34 | 92 |
isPlaying = false; |
3 | 93 |
try |
94 |
{ |
|
95 |
MediaElementVideo.Pause(); |
|
96 |
} |
|
34 | 97 |
catch (Exception exx) { } |
3 | 98 |
} |
99 |
||
100 |
} |
|
101 |
||
102 |
private void ButtonPlayPause_Click(object sender, RoutedEventArgs e) |
|
103 |
{ |
|
34 | 104 |
if (!isPlaying)//Play |
3 | 105 |
{ |
34 | 106 |
isPlaying = true; |
3 | 107 |
try |
108 |
{ |
|
109 |
MediaElementVideo.Play(); |
|
110 |
} |
|
34 | 111 |
catch (Exception ex) { } |
112 |
||
3 | 113 |
} |
114 |
else//Pause |
|
115 |
{ |
|
34 | 116 |
isPlaying = false; |
3 | 117 |
try |
118 |
{ |
|
119 |
MediaElementVideo.Pause(); |
|
120 |
} |
|
34 | 121 |
catch (Exception exx) { } |
122 |
//ButtonPlayPause.Background = FindResource("[Skin_1]_Play_button_xaml") as Brush; |
|
123 |
} |
|
124 |
} |
|
125 |
||
126 |
private void ButtonFastForward_Click(object sender, RoutedEventArgs e) |
|
127 |
{ |
|
128 |
if (MediaElementVideo.SpeedRatio <= 3) |
|
129 |
MediaElementVideo.SpeedRatio += 1; |
|
130 |
} |
|
131 |
||
132 |
private void ButtonFastForward_ContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e) |
|
133 |
{ |
|
134 |
if (MediaElementVideo.SpeedRatio <= 3) |
|
135 |
MediaElementVideo.SpeedRatio += 1; |
|
136 |
} |
|
137 |
||
138 |
private void ButtonRewind_Click(object sender, RoutedEventArgs e) |
|
139 |
{ |
|
140 |
//TimeSpan ts = new TimeSpan(0, 0, 0, 0); |
|
141 |
if (MediaElementVideo.SpeedRatio > 1) |
|
142 |
{ |
|
143 |
MediaElementVideo.SpeedRatio -= 1; |
|
3 | 144 |
} |
34 | 145 |
else |
146 |
{ |
|
147 |
MediaElementVideo.Position = MediaElementVideo.Position.Add(new TimeSpan(0, 0, 0, -5)); |
|
148 |
} |
|
149 |
} |
|
150 |
||
151 |
private void ButtonRewind_ContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e) |
|
152 |
{ |
|
153 |
||
154 |
//TimeSpan ts = new TimeSpan(0, 0, 0,0); |
|
155 |
if (MediaElementVideo.SpeedRatio > 1) |
|
156 |
{ |
|
157 |
MediaElementVideo.SpeedRatio -= 1; |
|
158 |
} |
|
159 |
else |
|
160 |
{ |
|
161 |
MediaElementVideo.Position = MediaElementVideo.Position.Add(new TimeSpan(0, 0, 0, -5)); |
|
162 |
} |
|
163 |
} |
|
164 |
||
165 |
private void MediaElementVideo_MediaOpened(object sender, RoutedEventArgs e) |
|
166 |
{ |
|
167 |
OnPlayerOpened(); |
|
168 |
} |
|
169 |
protected virtual void OnPlayerOpened() |
|
170 |
{ |
|
171 |
if(PlayerOpened!=null) |
|
172 |
PlayerOpened(this, new EventArgs()); |
|
3 | 173 |
} |
174 |
} |
|
175 |
} |