From 294a18e7c2319f9d80d053a97e61792894030f11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=BD=87=E9=98=B3?= Date: Tue, 4 Jun 2024 11:35:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=A6=96=E9=A0=BB=E6=92=AD?= =?UTF-8?q?=E6=94=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CPF_Cef/AksVideoPlayer.cs | 122 ++++++++++++++++++++++++++++++++++++++ CPF_Cef/FrmMain.cs | 12 +--- CPF_Cef/MainModel.cs | 80 ++++++++++++++----------- CPF_Cef/Parame.cs | 2 +- 4 files changed, 172 insertions(+), 44 deletions(-) create mode 100644 CPF_Cef/AksVideoPlayer.cs diff --git a/CPF_Cef/AksVideoPlayer.cs b/CPF_Cef/AksVideoPlayer.cs new file mode 100644 index 0000000..5448a83 --- /dev/null +++ b/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 + { + /// + /// apt-get install libvlc-dev + /// apt-get install vlc + /// + 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" }; + } +} diff --git a/CPF_Cef/FrmMain.cs b/CPF_Cef/FrmMain.cs index a872fba..e7ac4a1 100644 --- a/CPF_Cef/FrmMain.cs +++ b/CPF_Cef/FrmMain.cs @@ -32,14 +32,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser ShowInTaskbar = true; //WindowState = WindowState.FullScreen; WindowState = WindowState.Maximized; - Parame.videoV = new VideoView - { - Name = "player", - PresenterFor = this, - MarginTop = 0, - Width = 300, - Height = 300 - }; + Children.Add( new Border { @@ -97,6 +90,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser //SetTaskStatus.Showtask(); Parame.webBrowser.LoadEnd += WebBrowser_LoadEnd; this.Closing += MainWindow_Closing; + Parame.frm = this; } //关闭事件 @@ -145,7 +139,7 @@ namespace AKS.EnterpriseLibrary.WebBrowser } catch { } } - + private void CusRequest_CusResquestEvent(CefPostData postData, CefRequest request) { string postParams = string.Empty; diff --git a/CPF_Cef/MainModel.cs b/CPF_Cef/MainModel.cs index 475c126..46a51b2 100644 --- a/CPF_Cef/MainModel.cs +++ b/CPF_Cef/MainModel.cs @@ -6,6 +6,7 @@ using Fleck; using LibVLCSharp.Shared; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using SkiaSharp; using System; using System.Collections.Generic; using System.Diagnostics; @@ -60,7 +61,6 @@ namespace AKS.EnterpriseLibrary.WebBrowser //返回内容 string result = string.Empty; content = Base64str2(content); - // Log.Info("收到请求:" + socket.ConnectionInfo.ClientIpAddress + " 请求参数:" + content); if (!string.IsNullOrEmpty(content)) { try @@ -71,12 +71,6 @@ namespace AKS.EnterpriseLibrary.WebBrowser }); if (json != null) { - //释放所有硬件 - Task.Run(() => - { - HttpResponseClose(); - }); - @event8.WaitOne(); //接收指令和参数 string keycode = json.code; switch (keycode) @@ -155,7 +149,10 @@ namespace AKS.EnterpriseLibrary.WebBrowser //播放:{ "code":"aks100114","text":"你好!","ispaye":false,"ywid":"1234567890"}, case "aks100114": result = payleTextByWav(content); - //Log.Info("文字语音播报返回:" + result); + break; + //播放:{ "code":"aks100115","title":"測試","url":"http://127.0.0.1/test.mp4"}, + case "aks100115": + result = playVideo(content); break; default: result = "{\"timestamp\":\"" + Utils.GetTimestamp() + "\",\"keycode\":\"" + "" + "\",\"message\":\"Falied\",\"code\":\"400\",\"status\":false,\"data\":\"无效指令\"}"; @@ -643,6 +640,44 @@ namespace AKS.EnterpriseLibrary.WebBrowser } } + + /// + /// 播放视频 (已国产化) + /// + /// + /// + 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; + } + } + /// /// aks100106指纹 (已国产化,未完成测试) /// @@ -1466,9 +1501,9 @@ namespace AKS.EnterpriseLibrary.WebBrowser { var httpClient = new HttpClient(); var uploader = new ChunkedUpload(httpClient); - await uploader.PublicSign("close", 2, 0); - await uploader.PublicFinger("close", 2, 0); - await uploader.PublicIdcard("close", 2, 0); + await uploader.PublicSign("close", 2, 5); + await uploader.PublicFinger("close", 2, 5); + await uploader.PublicIdcard("close", 2, 5); @event8.Set(); } catch (Exception ex) @@ -1816,29 +1851,6 @@ namespace AKS.EnterpriseLibrary.WebBrowser } } - /// - /// 播放语音文件 - /// - /// - 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); - } - } - /// /// string 转换为 base64 /// diff --git a/CPF_Cef/Parame.cs b/CPF_Cef/Parame.cs index e88e202..ef37542 100644 --- a/CPF_Cef/Parame.cs +++ b/CPF_Cef/Parame.cs @@ -14,8 +14,8 @@ namespace AksWebBrowser { public static IWebSocketConnection socket { get; set; } public static TcpClient tcpClient { get; set; } - public static VideoView videoV { get; set; } public static CusWebBrowser webBrowser { get; set; } + public static Window frm { get; set; } public static List FuncObject { get; set; } //接口地址 public static string apiUrl = "http://192.168.0.34:92";