author | cavaliet |
Thu, 17 Sep 2009 17:25:05 +0200 | |
changeset 75 | 99d003723474 |
parent 49 | b23aa9d09ac1 |
child 77 | e95e916eb018 |
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 |
|
24 |
public UserControlPlayer() |
|
25 |
{ |
|
26 |
this.InitializeComponent(); |
|
27 |
initPlayer(); |
|
34 | 28 |
} |
3 | 29 |
|
34 | 30 |
#region Properties |
31 |
public double TotalMilliseconds |
|
32 |
{ |
|
33 |
get |
|
34 |
{ |
|
35 |
return MediaElementVideo.NaturalDuration.TimeSpan.TotalMilliseconds; |
|
36 |
} |
|
37 |
} |
|
38 |
public MediaElement Player |
|
39 |
{ |
|
40 |
get |
|
41 |
{ |
|
42 |
return MediaElementVideo; |
|
43 |
} |
|
44 |
set |
|
45 |
{ |
|
46 |
MediaElementVideo= value; |
|
47 |
} |
|
48 |
} |
|
49 |
||
50 |
#endregion |
|
51 |
||
52 |
||
53 |
#region Methodes |
|
3 | 54 |
void initPlayer() |
34 | 55 |
{ |
3 | 56 |
//init player |
34 | 57 |
isPlaying = false; |
41 | 58 |
//Pour se diriger vers le Dossier ressources du projet et non le bin/ressources |
49 | 59 |
//DirectoryInfo info = Directory.GetParent(@"."); |
60 |
FileInfo assemblyPath = new FileInfo(Assembly.GetExecutingAssembly().Location); |
|
61 |
DirectoryInfo info = assemblyPath.Directory; |
|
75
99d003723474
data binding second step. we can add annotation by clicking on menu buttons or timeline.
cavaliet
parents:
49
diff
changeset
|
62 |
MediaElementVideo.Source = new Uri(@"" + info.FullName.ToString() + "\\Resources\\oneflat.wmv", UriKind.Relative); |
3 | 63 |
MediaElementVideo.LoadedBehavior = MediaState.Manual; |
34 | 64 |
MediaElementVideo.UnloadedBehavior = MediaState.Manual; |
65 |
MediaElementVideo.ScrubbingEnabled= true; |
|
3 | 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 |
} |
178 |
} |
|
179 |
} |