230 lines
7.8 KiB
C#
230 lines
7.8 KiB
C#
using System;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
using System.Windows.Forms;
|
|
using LibVLCSharp.Shared;
|
|
using Tech_Demo.Properties;
|
|
using Vlc.DotNet.Forms;
|
|
|
|
namespace Tech_Demo
|
|
{
|
|
public partial class PlayerView : UserControl
|
|
{
|
|
/**
|
|
* 单画面模式
|
|
*/
|
|
public Boolean singleMode;
|
|
|
|
/**
|
|
* 静音
|
|
*/
|
|
public Boolean mute;
|
|
|
|
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)
|
|
{
|
|
// 复合画面
|
|
this.singleMode = false;
|
|
panel2.Dispose();
|
|
videoView.Dispose();
|
|
videoView.MediaPlayer.Dispose();
|
|
foreach (Control panel2Control in panel2.Controls)
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
private void button5_Click(object sender, EventArgs e)
|
|
{
|
|
// 单画面模式
|
|
this.singleMode = true;
|
|
// todo
|
|
}
|
|
|
|
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=100", ":rtsp-tcp"
|
|
}; // { ":network-caching=100", ":rtsp -tcp", ":no-audio" }; // --avcodec-hw={any,d3d11va,dxva2,none}
|
|
// var videoUri = new Uri(@"rtsp://admin:abc123456@192.168.1.233:554/h264/ch33/main/av_stream");
|
|
var videoUri = new Uri(@"rtsp://10.211.55.2:8554/rains");
|
|
if (videoView.MediaPlayer == null)
|
|
{
|
|
var libVlc = new LibVLC(enableDebugLogs: true);
|
|
var media = new Media(libVlc, videoUri, options);
|
|
var mediaPlayer = new MediaPlayer(media);
|
|
videoView.MediaPlayer = mediaPlayer;
|
|
}
|
|
|
|
// 播放器结束播放
|
|
if (videoView.MediaPlayer.State == VLCState.Ended)
|
|
{
|
|
Console.WriteLine("视频播放");
|
|
videoView.MediaPlayer.Play();
|
|
}
|
|
|
|
if (videoView.MediaPlayer.State == VLCState.Playing)
|
|
{
|
|
// 暂停
|
|
Console.WriteLine("视频暂停");
|
|
videoView.MediaPlayer.Pause();
|
|
}
|
|
|
|
if (videoView.MediaPlayer.State == VLCState.Paused ||
|
|
videoView.MediaPlayer.State == VLCState.NothingSpecial)
|
|
{
|
|
// 播放
|
|
videoView.MediaPlayer.Play();
|
|
}
|
|
|
|
// videoView.MediaPlayer.Play();
|
|
Console.WriteLine("mediaPlay:" + videoView.MediaPlayer.State);
|
|
}
|
|
|
|
private void videoView_Click(object sender, EventArgs e)
|
|
{
|
|
}
|
|
|
|
private void vlcControl_Click_2(object sender, EventArgs e)
|
|
{
|
|
throw new System.NotImplementedException();
|
|
}
|
|
|
|
private void panel1_Paint(object sender, PaintEventArgs e)
|
|
{
|
|
throw new System.NotImplementedException();
|
|
}
|
|
|
|
private void pictureBox1_Click(object sender, EventArgs e)
|
|
{
|
|
System.ComponentModel.ComponentResourceManager resources =
|
|
new System.ComponentModel.ComponentResourceManager(typeof(PlayerView));
|
|
if (videoView.MediaPlayer != null)
|
|
{
|
|
if ( videoView.MediaPlayer.Mute)
|
|
{
|
|
videoView.MediaPlayer.Mute = false;
|
|
this.muteBtn.Image = (System.Drawing.Image)resources.GetObject("muteBtn.InitialImage");
|
|
}
|
|
else
|
|
{
|
|
videoView.MediaPlayer.Mute = true;
|
|
this.muteBtn.Image = Properties.Resources.muteBtn_mute;
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
private void button3_Click(object sender, EventArgs e)
|
|
{
|
|
var videoViewMediaPlayer = this.videoView.MediaPlayer;
|
|
videoViewMediaPlayer.TakeSnapshot(0,"./1.jpg", 0, 0);
|
|
}
|
|
}
|
|
} |