123 lines
3.5 KiB
C#
123 lines
3.5 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.ComponentModel;
|
|||
|
|
using System.Data;
|
|||
|
|
using System.Drawing;
|
|||
|
|
using System.IO;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Net.NetworkInformation;
|
|||
|
|
using System.Reflection;
|
|||
|
|
using System.Text;
|
|||
|
|
using System.Windows.Forms;
|
|||
|
|
using System.Windows.Media;
|
|||
|
|
|
|||
|
|
namespace Nanji_Island
|
|||
|
|
{
|
|||
|
|
public partial class Form3 : Form
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
public Form3()
|
|||
|
|
{
|
|||
|
|
InitializeComponent();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void btnOpen_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
using (OpenFileDialog ofd = new OpenFileDialog())
|
|||
|
|
{
|
|||
|
|
ofd.Filter = "mp4文件|*.mp4|avi 文件 | *.avi";
|
|||
|
|
if (ofd.ShowDialog(this) == DialogResult.OK)
|
|||
|
|
{
|
|||
|
|
vlcControl1.Play(new System.IO.FileInfo(ofd.FileName));
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void vlcControl1_VlcLibDirectoryNeeded(object sender, Vlc.DotNet.Forms.VlcLibDirectoryNeededEventArgs e)
|
|||
|
|
{
|
|||
|
|
//获取当前路径
|
|||
|
|
var currentAssembly = Assembly.GetEntryAssembly();
|
|||
|
|
var currentDirectory = new FileInfo(currentAssembly.Location).DirectoryName;
|
|||
|
|
//获取对应平台的vlclib路径
|
|||
|
|
e.VlcLibDirectory = new DirectoryInfo(Path.Combine(currentDirectory, "libvlc", IntPtr.Size == 4 ? "win-x86": "win-x64"));
|
|||
|
|
//如果不存在 手动指定路径
|
|||
|
|
if (!e.VlcLibDirectory.Exists)
|
|||
|
|
{
|
|||
|
|
var folderBrowserDialog = new FolderBrowserDialog();
|
|||
|
|
folderBrowserDialog.Description = "Select Vlc libraries folder.";
|
|||
|
|
folderBrowserDialog.RootFolder = Environment.SpecialFolder.Desktop;
|
|||
|
|
folderBrowserDialog.ShowNewFolderButton = true;
|
|||
|
|
if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
|
|||
|
|
{
|
|||
|
|
e.VlcLibDirectory = new DirectoryInfo(folderBrowserDialog.SelectedPath);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void btnPlay_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
string sout = ":rtsp-tcp";
|
|||
|
|
vlcControl1.Play(new Uri("rtsp://192.168.1.168/0"),sout);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void btnPause_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
vlcControl1.Pause();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void btnStop_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
vlcControl1.Stop();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
private bool PingIp(string strIP)
|
|||
|
|
{
|
|||
|
|
bool bRet = false;
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
Ping pingSend = new Ping();
|
|||
|
|
PingReply reply = pingSend.Send(strIP, 1000);
|
|||
|
|
if (reply.Status == IPStatus.Success)
|
|||
|
|
bRet = true;
|
|||
|
|
}
|
|||
|
|
catch (Exception)
|
|||
|
|
{
|
|||
|
|
bRet = false;
|
|||
|
|
}
|
|||
|
|
return bRet;
|
|||
|
|
}
|
|||
|
|
bool a = false;
|
|||
|
|
private void timer1_Tick(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
Console.WriteLine(PingIp("192.168.1.168"));
|
|||
|
|
if (PingIp("192.168.1.168") == false)
|
|||
|
|
{
|
|||
|
|
vlcControl1.Stop();
|
|||
|
|
a = false;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
if (a == true)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
string sout = ":rtsp-tcp";
|
|||
|
|
vlcControl1.Play(new Uri("rtsp://192.168.1.168/0"), sout);
|
|||
|
|
a = true;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void Form3_Load(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|