Browse Source

新增視頻播放

master
胡超1 1 year ago
parent
commit
294a18e7c2
  1. 122
      CPF_Cef/AksVideoPlayer.cs
  2. 12
      CPF_Cef/FrmMain.cs
  3. 80
      CPF_Cef/MainModel.cs
  4. 2
      CPF_Cef/Parame.cs

122
CPF_Cef/AksVideoPlayer.cs

@ -0,0 +1,122 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CPF;
using CPF.Drawing;
using CPF.Controls;
using CPF.Shapes;
using CPF.Styling;
using CPF.Animation;
using CPF.Svg;
using CPF.Input;
using static System.Net.Mime.MediaTypeNames;
namespace AKS.EnterpriseLibrary.WebBrowser
{
public class AksVideoPlayer : Control
{
/// <summary>
/// apt-get install libvlc-dev
/// apt-get install vlc
/// </summary>
public string videoTitle = string.Empty;
public string url = string.Empty;
private VideoView vplayer = null;
public AksVideoPlayer(Window window, string _videoTitle,string _url)
{
vplayer = new VideoView
{
Name = "player",
PresenterFor = this,
MarginTop = 50,
Size = SizeField.Fill,
Background = Color.Silver
};
videoTitle = _videoTitle;
url = _url;
this.window = window;
window.Children.Add(mask);
window.Children.Add(this);
mask.TransitionValue(a => a.Background, "0,0,0,100", TimeSpan.FromSeconds(0.3), null, AnimateMode.Linear);
//this.TransitionValue(a => a.MarginTop, 100, TimeSpan.FromSeconds(0.3), new PowerEase { }, AnimateMode.EaseOut);
mask.MouseDown += Mask_MouseDown;
}
private void Mask_MouseDown(object sender, MouseButtonEventArgs e)
{
window.DragMove();
}
private Window window;
protected override void OnInitialized()
{
base.OnInitialized();
//@"http://192.168.0.34:92/CaseFile/card/2024-06-03/20240603120112952.mp4"
vplayer.Play(new Uri(url));//播放
}
protected override void InitializeComponent()
{
IsAntiAlias = true;
CornerRadius = "3,3,3,3";
Height = "80%";
Width = "70%";
Background = "#2c2c2c";
ZIndex = 100;
Children.Add(new TextBlock
{
MarginRight = 12f,
MarginTop = 10f,
Text = "关闭",
FontSize = 16,
Cursor = CPF.Cursors.Hand,
Foreground = Color.White,
ZIndex = 101,
Commands =
{
{
nameof(MouseDown),
(s,e)=>Close()
}
},
Triggers =
{
{
nameof(IsMouseOver),
Relation.Me,
null,
(nameof(Foreground),Color.White)
}
}
});
Children.Add(new TextBlock
{
FontSize = 16f,
MarginLeft = 12.6f,
MarginTop = 9.6f,
Foreground = Color.White,
Text = videoTitle,
});
Children.Add(vplayer);
}
public void Close()
{
vplayer.Stop();
mask.TransitionValue(a => a.Background, "0,0,0,0", TimeSpan.FromSeconds(0.3), null, AnimateMode.Linear, () =>
{
window.Children.Remove(mask);
});
this.TransitionValue(a => a.MarginTop, -100, TimeSpan.FromSeconds(0.3), new PowerEase { }, AnimateMode.EaseIn, () =>
{
window.Children.Remove(this);
});
}
Control mask = new Control { Size = SizeField.Fill, ZIndex = 100, Background = "#00000000" };
}
}

12
CPF_Cef/FrmMain.cs

@ -32,14 +32,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser
ShowInTaskbar = true; ShowInTaskbar = true;
//WindowState = WindowState.FullScreen; //WindowState = WindowState.FullScreen;
WindowState = WindowState.Maximized; WindowState = WindowState.Maximized;
Parame.videoV = new VideoView
{
Name = "player",
PresenterFor = this,
MarginTop = 0,
Width = 300,
Height = 300
};
Children.Add( Children.Add(
new Border new Border
{ {
@ -97,6 +90,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser
//SetTaskStatus.Showtask(); //SetTaskStatus.Showtask();
Parame.webBrowser.LoadEnd += WebBrowser_LoadEnd; Parame.webBrowser.LoadEnd += WebBrowser_LoadEnd;
this.Closing += MainWindow_Closing; this.Closing += MainWindow_Closing;
Parame.frm = this;
} }
//关闭事件 //关闭事件
@ -145,7 +139,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser
} }
catch { } catch { }
} }
private void CusRequest_CusResquestEvent(CefPostData postData, CefRequest request) private void CusRequest_CusResquestEvent(CefPostData postData, CefRequest request)
{ {
string postParams = string.Empty; string postParams = string.Empty;

80
CPF_Cef/MainModel.cs

@ -6,6 +6,7 @@ using Fleck;
using LibVLCSharp.Shared; using LibVLCSharp.Shared;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using SkiaSharp;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
@ -60,7 +61,6 @@ namespace AKS.EnterpriseLibrary.WebBrowser
//返回内容 //返回内容
string result = string.Empty; string result = string.Empty;
content = Base64str2(content); content = Base64str2(content);
// Log.Info("收到请求:" + socket.ConnectionInfo.ClientIpAddress + " 请求参数:" + content);
if (!string.IsNullOrEmpty(content)) if (!string.IsNullOrEmpty(content))
{ {
try try
@ -71,12 +71,6 @@ namespace AKS.EnterpriseLibrary.WebBrowser
}); });
if (json != null) if (json != null)
{ {
//释放所有硬件
Task.Run(() =>
{
HttpResponseClose();
});
@event8.WaitOne();
//接收指令和参数 //接收指令和参数
string keycode = json.code; string keycode = json.code;
switch (keycode) switch (keycode)
@ -155,7 +149,10 @@ namespace AKS.EnterpriseLibrary.WebBrowser
//播放:{ "code":"aks100114","text":"你好!","ispaye":false,"ywid":"1234567890"}, //播放:{ "code":"aks100114","text":"你好!","ispaye":false,"ywid":"1234567890"},
case "aks100114": case "aks100114":
result = payleTextByWav(content); result = payleTextByWav(content);
//Log.Info("文字语音播报返回:" + result); break;
//播放:{ "code":"aks100115","title":"測試","url":"http://127.0.0.1/test.mp4"},
case "aks100115":
result = playVideo(content);
break; break;
default: default:
result = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + "" + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"无效指令\"}"; result = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + "" + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"无效指令\"}";
@ -643,6 +640,44 @@ namespace AKS.EnterpriseLibrary.WebBrowser
} }
} }
/// <summary>
/// 播放视频 (已国产化)
/// </summary>
/// <param name="paramsString"></param>
/// <returns></returns>
private static string playVideo(string content)
{
try
{
var param = content.ConvertToAnonymousType(new
{
code = default(string),
title = default(string),
url = default(string)
});
if (!isFuncisFuncObject("playVideo"))
{
return "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + "视频播放设备未授权使用" + "\"}";
}
else
{
new AksVideoPlayer(Parame.frm, param.title, param.url);
string result = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"jpg\",\"data\":\"" + "播放成功" + "\"}";
SubmitLogs(result, "playVideo");
return result;
}
}
catch (Exception ex)
{
//Log.Error("关闭签字版异常: " + ex.Message + "");
string result = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}";
SubmitLogs(result, "playVideo");
return result;
}
}
/// <summary> /// <summary>
/// aks100106指纹 (已国产化,未完成测试) /// aks100106指纹 (已国产化,未完成测试)
/// </summary> /// </summary>
@ -1466,9 +1501,9 @@ namespace AKS.EnterpriseLibrary.WebBrowser
{ {
var httpClient = new HttpClient(); var httpClient = new HttpClient();
var uploader = new ChunkedUpload(httpClient); var uploader = new ChunkedUpload(httpClient);
await uploader.PublicSign("close", 2, 0); await uploader.PublicSign("close", 2, 5);
await uploader.PublicFinger("close", 2, 0); await uploader.PublicFinger("close", 2, 5);
await uploader.PublicIdcard("close", 2, 0); await uploader.PublicIdcard("close", 2, 5);
@event8.Set(); @event8.Set();
} }
catch (Exception ex) catch (Exception ex)
@ -1816,29 +1851,6 @@ namespace AKS.EnterpriseLibrary.WebBrowser
} }
} }
/// <summary>
/// 播放语音文件
/// </summary>
/// <param name="ispaly"></param>
public static void AutoAudio(bool ispaly, string path)
{
try
{
if (ispaly)
{
Parame.videoV.Play(new Uri(path));//播放
}
else
{
Parame.videoV.Pause();//停止
}
}
catch (Exception ex)
{
//Log.Error("播放语音文件异常:" + ex.Message);
}
}
/// <summary> /// <summary>
/// string 转换为 base64 /// string 转换为 base64
/// </summary> /// </summary>

2
CPF_Cef/Parame.cs

@ -14,8 +14,8 @@ namespace AksWebBrowser
{ {
public static IWebSocketConnection socket { get; set; } public static IWebSocketConnection socket { get; set; }
public static TcpClient tcpClient { get; set; } public static TcpClient tcpClient { get; set; }
public static VideoView videoV { get; set; }
public static CusWebBrowser webBrowser { get; set; } public static CusWebBrowser webBrowser { get; set; }
public static Window frm { get; set; }
public static List<Func> FuncObject { get; set; } public static List<Func> FuncObject { get; set; }
//接口地址 //接口地址
public static string apiUrl = "http://192.168.0.34:92"; public static string apiUrl = "http://192.168.0.34:92";

Loading…
Cancel
Save