132 lines
4.9 KiB
C#
132 lines
4.9 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
using System.Windows.Forms;
|
|
using LibVLCSharp.Shared;
|
|
using Vlc.DotNet.Forms;
|
|
|
|
namespace Tech_Demo
|
|
{
|
|
public partial class PlayerView : UserControl
|
|
{
|
|
public PlayerView()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void PlayerView_Load(object sender, EventArgs e)
|
|
{
|
|
// string[] options = { ":network-caching=100", ":rtsp-tcp"};// { ":network-caching=100", ":rtsp -tcp", ":no-audio" }; // --avcodec-hw={any,d3d11va,dxva2,none}
|
|
// var videoUri = new Uri(@"rtsp://127.0.0.1:8554/rains");
|
|
// vlcControl.Play(videoUri, options);
|
|
// vlcControl.Controls
|
|
|
|
// using(SaveFileDialog sfd = new SaveFileDialog())
|
|
// {
|
|
// sfd.Filter = "jpg文件 | *.jpg";
|
|
// if(sfd.ShowDialog() == DialogResult.OK)
|
|
// {
|
|
// vlcControl.TakeSnapshot(sfd.FileName);
|
|
// }
|
|
// }
|
|
}
|
|
|
|
private void vlcControl_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void vlcControl_VlcLibDirectoryNeeded(object sender, VlcLibDirectoryNeededEventArgs e)
|
|
{
|
|
var currentAssembly = Assembly.GetEntryAssembly();
|
|
var currentDirectory = new FileInfo(currentAssembly.Location).DirectoryName;
|
|
|
|
if (currentDirectory == null)
|
|
return;
|
|
if (IntPtr.Size == 4)
|
|
e.VlcLibDirectory = new DirectoryInfo(Path.GetFullPath(@".\libvlc\win-x86\"));
|
|
else
|
|
e.VlcLibDirectory = new DirectoryInfo(Path.GetFullPath(@".\libvlc\win-x64\"));
|
|
|
|
if (!e.VlcLibDirectory.Exists)
|
|
{
|
|
var folderBrowserDialog = new System.Windows.Forms.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 playBtn_Click(object sender, EventArgs e)
|
|
{
|
|
string[] options = { ":network-caching=10", ":rtsp-tcp"};// { ":network-caching=100", ":rtsp -tcp", ":no-audio" }; // --avcodec-hw={any,d3d11va,dxva2,none}
|
|
var videoUri = new Uri(@"rtsp://127.0.0.1:8554/rains");
|
|
vlcControl.Play(videoUri, options);
|
|
Console.WriteLine("播放rtsp视频");
|
|
}
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
// this.vlcControl.Dock = DockStyle.Left;
|
|
// this.vlcControl.Width = this.panel2.Width / 3 * 2;
|
|
// if (this.panel2.Controls.Count == 1)
|
|
// {
|
|
// var ucOverview = new UCOverview();
|
|
// ucOverview.Dock = DockStyle.Right;
|
|
// ucOverview.Width = this.panel2.Width / 3 * 1;
|
|
// this.panel2.Controls.Add(ucOverview);
|
|
//
|
|
// }
|
|
this.panel2.Refresh();
|
|
Console.WriteLine("按钮被点击了");
|
|
}
|
|
|
|
private void button1_Click_1(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void button4_Click(object sender, EventArgs e)
|
|
{
|
|
throw new System.NotImplementedException();
|
|
}
|
|
|
|
private void button5_Click(object sender, EventArgs e)
|
|
{
|
|
throw new System.NotImplementedException();
|
|
}
|
|
|
|
private void button6_Click(object sender, EventArgs e)
|
|
{
|
|
string[] options = { ":network-caching=10", ":rtsp-tcp"};// { ":network-caching=100", ":rtsp -tcp", ":no-audio" }; // --avcodec-hw={any,d3d11va,dxva2,none}
|
|
var videoUri = new Uri(@"rtsp://127.0.0.1:8554/rains");
|
|
vlcControl.Audio.IsMute = false;
|
|
vlcControl.Play(videoUri, options);
|
|
Console.WriteLine("播放rtsp视频");
|
|
|
|
}
|
|
|
|
private void vlcControl_Click_1(object sender, EventArgs e)
|
|
{
|
|
throw new System.NotImplementedException();
|
|
}
|
|
|
|
private void button7_Click(object sender, EventArgs e)
|
|
{
|
|
string[] options = { ":network-caching=10", ":rtsp-tcp"};// { ":network-caching=100", ":rtsp -tcp", ":no-audio" }; // --avcodec-hw={any,d3d11va,dxva2,none}
|
|
var videoUri = new Uri(@"rtsp://127.0.0.1:8554/rains2");
|
|
var libVlc = new LibVLC(enableDebugLogs: true);
|
|
var media = new Media(libVlc,videoUri,options);
|
|
var mediaPlayer = new MediaPlayer(media);
|
|
videoView.MediaPlayer = mediaPlayer;
|
|
videoView.MediaPlayer.Play();
|
|
}
|
|
}
|
|
} |