提问人:Kaloschke 提问时间:1/31/2021 更新时间:1/31/2021 访问量:51
C# 应用 - 视频流在第一次尝试时不启动
C# App - Video stream does not start at 1st attempt
问:
我的 C# 应用程序以最小化方式启动,并在发生特定事件时显示网络摄像头的视频流 5 秒钟。之后,它再次最小化。这效果很好,但仅限于第 2 个事件。在第一次调用时,仅显示一个空窗体。 是否有可以添加 videoSourcePlayer1.Show() 的事件,以便在 1 事件中也显示某些内容?它在Form1_Shown事件中不执行任何操作。
我的代码:
...
private readonly UdpClient udp = new UdpClient(port);
public IntPtr myHandle;
public void wait(int milliseconds)
{
...
}
private void StartListening()
{
this.udp.BeginReceive(Receive, new object());
}
private void Receive(IAsyncResult ar)
{
IPEndPoint ip = new IPEndPoint(IPAddress.Parse(ip), port);
byte[] bytes = udp.EndReceive(ar, ref ip);
string message = Encoding.ASCII.GetString(bytes);
if (message == "ON")
{
ShowWindow(myHandle, SW_RESTORE);
Thread.Sleep(50);
SetForegroundWindow(myHandle);
wait(5000);
ShowWindow(myHandle, SW_SHOWMINIMIZED);
}
StartListening();
}
private void Form1_Load(object sender, EventArgs e)
{
myHandle = this.Handle;
videoSourcePlayer1.VideoSource = new MJPEGStream("http://ip/video.mjpg");
videoSourcePlayer1.Start();
this.WindowState = FormWindowState.Minimized;
StartListening();
}
private void Form1_Resize(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Minimized)
{
Hide();
notifyIcon1.Visible = true;
videoSourcePlayer1.Hide();
}
if (this.WindowState == FormWindowState.Normal)
{
Show();
this.WindowState = FormWindowState.Normal;
notifyIcon1.Visible = false;
videoSourcePlayer1.Show();
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
videoSourcePlayer1.Stop();
}
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
{
Show();
this.WindowState = FormWindowState.Normal;
notifyIcon1.Visible = false;
}
}
我能做些什么?
答:
0赞
petabyte
1/31/2021
#1
添加此方法以继续流
private void bntContinue_Click(object sender, EventArgs e)
{
videoSourcePlayer1.Continue();
}
评论
0赞
Kaloschke
1/31/2021
我不想点击流:-(
0赞
petabyte
1/31/2021
代替 videoSourcePlayer1.Show();将其更改为 form2.show ( );(表单的名称),因为它用于从一种表单移动到另一种表单
0赞
Kaloschke
1/31/2021
对不起,我不明白。我只有一种形式。我应该创建第二个吗?
1赞
Kaloschke
1/31/2021
#2
明白了。我在 Form1_Resize 中更改了执行顺序并添加了延迟。
if (this.WindowState == FormWindowState.Normal)
{
videoSourcePlayer1.Show();
Thread.Sleep(250);
this.WindowState = FormWindowState.Normal;
notifyIcon1.Visible = false;
Show();
}
评论