forked from polyv/csharp-vod-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UserControl1.xaml.cs
288 lines (246 loc) · 7.85 KB
/
UserControl1.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
using System;
using System.Windows;
using System.Windows.Controls;
using System.IO;
using System.Timers;
using System.ComponentModel;
namespace PolyvPlayerDemoWinform
{
/// <summary>
/// UserControl1.xaml 的交互逻辑
/// </summary>
public partial class UserControl1 : UserControl
{
static Application app;
public delegate void OnMediaOpenedHandler(TimeSpan durationPositon);
public event OnMediaOpenedHandler OnMediaOpened;
public bool isMouseDown = false;
public UserControl1()
{
InitializeComponent();
if (null == System.Windows.Application.Current)
{
app = new System.Windows.Application();
app.ShutdownMode = ShutdownMode.OnExplicitShutdown;
}
try
{
//ffmpeg库路径,不能为空
PolyvPlayerSDK.MediaElement.FFmpegDirectory = @".\ffmpeg";
}
catch
{
}
//播放初始化账号信息,不能为空
string userId = "";
string secretkey = "";
string readToken = "";
Media.initAccountInfo(userId, secretkey, readToken);
//初始化观看者信息,观看者的ip,不能为空
string viewerIp = "1.1.1.1";
string viewerId = "";
string viewerName = "";
Media.initPlayerInfo(viewerIp, viewerId, viewerName);
Media.MediaOpening += Media_MediaOpening;
Media.MediaFailed += Media_MediaFailed;
Media.MediaEnded += MediaEndedEvent;
Media.MediaOpened += Media_MediaOpened;
}
private void MediaEndedEvent(object sender, System.Windows.RoutedEventArgs e)
{
}
private void Media_MediaOpening(object sender, PolyvPlayerSDK.MediaOpeningRoutedEventArgs e)
{
Media.mylog.Debug("Media_MediaOpening");
}
private void Media_MediaOpened(object sender, System.Windows.RoutedEventArgs e)
{
OnMediaOpened(Media.NaturalDuration.TimeSpan);
isMouseDown = false;
Media.mylog.Debug("Media_MediaOpened");
}
private void Media_MediaFailed(object sender, System.Windows.ExceptionRoutedEventArgs e)
{
Media.mylog.Error("Media_MediaFailed");
}
public int open(string vid,int playType,int bitRate)
{
System.Windows.Thickness nes = scrollingTextControl1.Margin;
nes.Left = 100;
nes.Top = 0;
nes.Right = 0;
nes.Bottom = 0;
scrollingTextControl1.Margin = nes;
//string directPaths = "C:/";
//Directory.SetCurrentDirectory(directPaths);
int ret = Media.PlayVideo(vid, bitRate, playType, "C:/");
return ret;
}
public void close()
{
Media.Close();
}
public void pause()
{
Media.Pause();
}
public void play()
{
Media.Play();
}
public void setVolume(double vol)
{
Media.Volume = vol;
}
public void setSpeedRatio(double speed)
{
Media.SpeedRatio = speed;
}
public void setPosition(long time)
{
Media.Position = TimeSpan.FromTicks((long)(TimeSpan.TicksPerSecond * (long)time));
}
public void closeWpfControl()
{
if (null == System.Windows.Application.Current)
{
new System.Windows.Application();
}
Application.Current.Shutdown();
}
public void runWpfControl()
{
//if (null == System.Windows.Application.Current)
//{
// new System.Windows.Application();
//}
//Application.Current.Run();
if (null == System.Windows.Application.Current)
{
new System.Windows.Application();
Application.Current.Run();
}
}
}
/// <summary>
/// Label走马灯自定义控件
/// </summary>
[System.Drawing.ToolboxBitmap(typeof(Label))] //设置工具箱中显示的图标
public class ScrollingTextControl : Label
{
/// <summary>
/// 定时器
/// </summary>
Timer MarqueeTimer = new Timer();
/// <summary>
/// 滚动文字源
/// </summary>
String _TextSource = "滚动文字源";
/// <summary>
/// 输出文本
/// </summary>
String _OutText = string.Empty;
/// <summary>
/// 过度文本存储
/// </summary>
string _TempString = string.Empty;
/// <summary>
/// 文字的滚动速度
/// </summary>
double _RunSpeed = 1000;
DateTime _SignTime;
bool _IfFirst = true;
/// <summary>
/// 滚动一循环字幕停留的秒数,单位为毫秒,默认值停留3秒
/// </summary>
int _StopSecond = 3000;
/// <summary>
/// 滚动一循环字幕停留的秒数,单位为毫秒,默认值停留3秒
/// </summary>
public int StopSecond
{
get { return _StopSecond; }
set
{
_StopSecond = value;
}
}
/// <summary>
/// 滚动的速度
/// </summary>
[Description("文字滚动的速度")] //显示在属性设计视图中的描述
public double RunSpeed
{
get { return _RunSpeed; }
set
{
_RunSpeed = value;
MarqueeTimer.Interval = _RunSpeed;
}
}
/// <summary>
/// 滚动文字源
/// </summary>
[Description("文字滚动的Text")]
public string TextSource
{
get { return _TextSource; }
set
{
_TextSource = value;
_TempString = _TextSource + " ";
_OutText = _TempString;
}
}
private string SetContent
{
get { return Content.ToString(); }
set
{
Content = value;
}
}
/// <summary>
/// 构造函数
/// </summary>
public ScrollingTextControl()
{
MarqueeTimer.Interval = _RunSpeed;//文字移动的速度
MarqueeTimer.Enabled = true; //开启定时触发事件
MarqueeTimer.Elapsed += new ElapsedEventHandler(MarqueeTimer_Elapsed);//绑定定时事件
this.Loaded += new RoutedEventHandler(ScrollingTextControl_Loaded);//绑定控件Loaded事件
}
void ScrollingTextControl_Loaded(object sender, RoutedEventArgs e)
{
_TextSource = SetContent;
_TempString = _TextSource + " ";
_OutText = _TempString;
_SignTime = DateTime.Now;
}
void MarqueeTimer_Elapsed(object sender, ElapsedEventArgs e)
{
if (string.IsNullOrEmpty(_OutText)) return;
if (_OutText.Substring(1) + _OutText[0] == _TempString)
{
if (_IfFirst)
{
_SignTime = DateTime.Now;
}
if ((DateTime.Now - _SignTime).TotalMilliseconds > _StopSecond)
{
_IfFirst = true; ;
}
else
{
_IfFirst = false;
return;
}
}
_OutText = _OutText.Substring(1) + _OutText[0];
Dispatcher.BeginInvoke(new Action(() =>
{
SetContent = _OutText;
}));
}
}
}