Ajoutez des fichiers projet.
This commit is contained in:
95
StreamViewer.cs
Normal file
95
StreamViewer.cs
Normal file
@@ -0,0 +1,95 @@
|
||||
using LibVLCSharp.Shared;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.DirectoryServices.ActiveDirectory;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace robospot_camera_finder
|
||||
{
|
||||
public partial class StreamViewer : Form
|
||||
{
|
||||
public LibVLC _libVLC;
|
||||
public MediaPlayer _mp;
|
||||
|
||||
string username = "admin";
|
||||
string password = "RoboSpot10";
|
||||
string cam_ip = "";
|
||||
|
||||
public StreamViewer(string name, string ip)
|
||||
{
|
||||
InitializeComponent();
|
||||
_libVLC = new LibVLC();
|
||||
_mp = new MediaPlayer(_libVLC);
|
||||
cam_ip = ip;
|
||||
|
||||
timerUpdateZoom.Start();
|
||||
updateZoomSlider();
|
||||
|
||||
videoView.MediaPlayer = _mp;
|
||||
var media = new Media(_libVLC, new Uri("rtsp://" + ip + "/profile2/media.smp"));
|
||||
media.AddOption(":network-caching=25");
|
||||
_mp.Play(media);
|
||||
media.Dispose();
|
||||
this.Text = name;
|
||||
}
|
||||
|
||||
private void updateZoomSlider()
|
||||
{
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://" + cam_ip + "/stw-cgi/ptzcontrol.cgi?msubmenu=query&action=view&Query=Zoom");
|
||||
request.Credentials = new NetworkCredential(username, password);
|
||||
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
||||
string text;
|
||||
using (var sr = new StreamReader(response.GetResponseStream())) { text = sr.ReadToEnd(); }
|
||||
string[] resp_lines = text.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
|
||||
string zoom_value = resp_lines[1].Substring(resp_lines[1].LastIndexOf('=') + 1);
|
||||
tbZoom.Value = int.Parse(zoom_value);
|
||||
|
||||
}
|
||||
|
||||
private void sendZoomValue(string zoom_pulse)
|
||||
{
|
||||
// clamp values to allowed range
|
||||
if (int.Parse(zoom_pulse) < 10)
|
||||
{
|
||||
zoom_pulse = "10";
|
||||
}
|
||||
if (int.Parse(zoom_pulse) > 9999)
|
||||
{
|
||||
zoom_pulse = "9999";
|
||||
}
|
||||
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://" + cam_ip + "/stw-cgi/ptzcontrol.cgi?msubmenu=absolute&action=control&ZoomPulse=" + zoom_pulse);
|
||||
request.Credentials = new NetworkCredential(username, password);
|
||||
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
||||
}
|
||||
|
||||
private void StreamViewer_FormClosed(object sender, FormClosedEventArgs e)
|
||||
{
|
||||
_mp.Stop();
|
||||
_mp.Dispose();
|
||||
_libVLC.Dispose();
|
||||
}
|
||||
|
||||
private void tbZoom_KeyUp(object sender, KeyEventArgs e)
|
||||
{
|
||||
sendZoomValue(tbZoom.Value.ToString());
|
||||
}
|
||||
|
||||
private void tbZoom_MouseUp(object sender, MouseEventArgs e)
|
||||
{
|
||||
sendZoomValue(tbZoom.Value.ToString());
|
||||
}
|
||||
|
||||
private void timerUpdateZoom_Tick(object sender, EventArgs e)
|
||||
{
|
||||
updateZoomSlider();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user