You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
273 lines
6.7 KiB
273 lines
6.7 KiB
3 years ago
|
using EC.Entity.Video;
|
||
|
using EC.Onvif;
|
||
|
using LibVLCSharp.Shared;
|
||
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Linq;
|
||
|
using System.Text;
|
||
|
using System.Threading.Tasks;
|
||
|
using System.Windows;
|
||
|
using System.Windows.Controls;
|
||
|
using System.Windows.Data;
|
||
|
using System.Windows.Documents;
|
||
|
using System.Windows.Input;
|
||
|
|
||
|
|
||
|
using System.Windows.Navigation;
|
||
|
using System.Windows.Shapes;
|
||
|
|
||
|
namespace ECMonitor.UC.Videos
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// UCRtspVlcVideo.xaml 的交互逻辑
|
||
|
/// </summary>
|
||
|
public partial class UCRtspVlcVideo : UserControl,IUCPlayer
|
||
|
{
|
||
|
|
||
|
LibVLC _libVLC;
|
||
|
MediaPlayer _mediaPlayer;
|
||
|
public string Message { get; set; }
|
||
|
|
||
|
public MonitorCamera Camera { get; set; }
|
||
|
private OnvifClient _onvifClient { get; set; }
|
||
|
public int VideoType { get; set; }
|
||
|
/// <summary>
|
||
|
/// 更新时间
|
||
|
/// </summary>
|
||
|
private DateTime upDateTime;
|
||
|
|
||
|
public UCRtspVlcVideo(double width, double height, int index, string aspectRatio = "4:3")
|
||
|
{
|
||
|
this.Width = width;
|
||
|
this.Height = height;
|
||
|
InitializeComponent();
|
||
|
this.Name = "UCVideoPlay" +index;
|
||
|
|
||
|
// "--no-audio" 没有声音
|
||
|
_libVLC = new LibVLC(enableDebugLogs: true, "--rtsp-frame-buffer-size=0", "--no-audio", "--quiet-synchro");
|
||
|
_mediaPlayer = new MediaPlayer(_libVLC);
|
||
|
_mediaPlayer.AspectRatio = aspectRatio;
|
||
|
|
||
|
videoView1.MediaPlayer = _mediaPlayer;
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
public void ReSetSize(double width, double height)
|
||
|
{
|
||
|
Width = width;
|
||
|
Height = height;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
/// <summary>
|
||
|
/// 播放
|
||
|
/// </summary>
|
||
|
/// <param name="ip">IP地址</param>
|
||
|
/// <param name="userName">用户</param>
|
||
|
/// <param name="passWord">密码</param>
|
||
|
//public void Play(string ip,string userName,string passWord)
|
||
|
//{
|
||
|
// this.Ip = ip;
|
||
|
// string url = string.Format(RTSPUrlFormat, userName, passWord, ip);
|
||
|
// Play(url);
|
||
|
//}
|
||
|
public bool Play(MonitorCamera camera)
|
||
|
{
|
||
|
if (IsPlaying())
|
||
|
{
|
||
|
Stop();
|
||
|
}
|
||
|
Camera = camera;
|
||
|
if (Camera == null)
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
videoView1.Height = this.ActualHeight - 3;
|
||
|
videoView1.Width = this.ActualWidth - 3;
|
||
|
|
||
|
string url = Camera.RtspURL();
|
||
|
var media = new Media(_libVLC, new Uri(url), "--newwork-caching=0", "--rtsp-frame-buffer-size=0", "--no-audio");
|
||
|
bool play= _mediaPlayer.Play(media);
|
||
|
//_mediaPlayer.ToggleFullscreen();
|
||
|
|
||
|
return play;
|
||
|
|
||
|
|
||
|
}
|
||
|
public bool Play()
|
||
|
{
|
||
|
|
||
|
if (Camera == null)
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
bool play = _mediaPlayer.Play();
|
||
|
_mediaPlayer.ToggleFullscreen();
|
||
|
return play;
|
||
|
}
|
||
|
public void Stop()
|
||
|
{
|
||
|
_mediaPlayer?.Stop();
|
||
|
}
|
||
|
|
||
|
public void UPDateTime()
|
||
|
{
|
||
|
upDateTime = new DateTime();
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 判断预警是否接触
|
||
|
/// </summary>
|
||
|
/// <returns></returns>
|
||
|
public bool IsTimeOut()
|
||
|
{
|
||
|
DateTime now = new DateTime();
|
||
|
double difSeconds = DateUnit.DateDiffSeconds(upDateTime, now);
|
||
|
return difSeconds > 30;
|
||
|
}
|
||
|
public string GetCameraIp() {
|
||
|
if (Camera != null)
|
||
|
{
|
||
|
return Camera.Ip;
|
||
|
}
|
||
|
return "";
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 播放器类型
|
||
|
/// </summary>
|
||
|
/// <returns></returns>
|
||
|
public int GetPlayerType()
|
||
|
{
|
||
|
return VideoType;
|
||
|
}
|
||
|
|
||
|
|
||
|
/// <summary>
|
||
|
/// 相机
|
||
|
/// </summary>
|
||
|
/// <returns></returns>
|
||
|
public MonitorCamera GetCamera()
|
||
|
{
|
||
|
return Camera;
|
||
|
}
|
||
|
|
||
|
public OnvifClient GetOnvifClient()
|
||
|
{
|
||
|
return _onvifClient;
|
||
|
}
|
||
|
|
||
|
public UserControl GetControl()
|
||
|
{
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
public string GetMessage()
|
||
|
{
|
||
|
return Message;
|
||
|
}
|
||
|
|
||
|
public string GetName()
|
||
|
{
|
||
|
return this.Name;
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 是否是空播放器
|
||
|
/// </summary>
|
||
|
/// <returns></returns>
|
||
|
public bool IsNullPlay()
|
||
|
{
|
||
|
return Camera == null;
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 是否正在播放
|
||
|
/// </summary>
|
||
|
/// <returns></returns>
|
||
|
public bool IsPlaying()
|
||
|
{
|
||
|
if (Camera == null|| _mediaPlayer==null)
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
return _mediaPlayer.IsPlaying;
|
||
|
}
|
||
|
private int listIndex = 0;
|
||
|
public int GetIndex()
|
||
|
{
|
||
|
return listIndex;
|
||
|
}
|
||
|
|
||
|
public void SetIndex(int index)
|
||
|
{
|
||
|
listIndex = index;
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 是否显示
|
||
|
/// </summary>
|
||
|
private bool IsShow = false;
|
||
|
|
||
|
public event EventHandler<int> PlayerMouseDown;
|
||
|
public event EventHandler<int> PlayerMouseDoubleClick;
|
||
|
public event EventHandler<int> OnFromClose;
|
||
|
|
||
|
public bool GetIsShow()
|
||
|
{
|
||
|
return IsShow;
|
||
|
}
|
||
|
public void SetIsShow(bool isShow)
|
||
|
{
|
||
|
IsShow = isShow;
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 设置窗体大小
|
||
|
/// </summary>
|
||
|
/// <param name="videoWidth"></param>
|
||
|
/// <param name="videoHeight"></param>
|
||
|
public void SetSize(double videoWidth, double videoHeight)
|
||
|
{
|
||
|
this.Width = videoWidth;
|
||
|
this.Height = videoHeight;
|
||
|
}
|
||
|
|
||
|
private void btnClose_Click(object sender, RoutedEventArgs e)
|
||
|
{
|
||
|
Stop();
|
||
|
}
|
||
|
|
||
|
private void btnPlay_Click(object sender, RoutedEventArgs e)
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
public void SetSelected(bool selected)
|
||
|
{
|
||
|
throw new NotImplementedException();
|
||
|
}
|
||
|
|
||
|
public bool Play(MonitorCamera camera, bool replay = false)
|
||
|
{
|
||
|
throw new NotImplementedException();
|
||
|
}
|
||
|
|
||
|
public bool SetMaximized(double width, double height)
|
||
|
{
|
||
|
throw new NotImplementedException();
|
||
|
}
|
||
|
|
||
|
public bool IxMaximized()
|
||
|
{
|
||
|
throw new NotImplementedException();
|
||
|
}
|
||
|
|
||
|
public void ShowMsg(string message)
|
||
|
{
|
||
|
throw new NotImplementedException();
|
||
|
}
|
||
|
}
|
||
|
}
|