batteryDiagnosis/Assets/Scripts/UI/UIPanel/UI_BGPanel.cs

312 lines
10 KiB
C#
Raw Blame History

using Hanatric.Unity.Video.FFmpegPlayer;
using Newtonsoft.Json;
using System.IO;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using Vuplex.WebView;
using static UnityEngine.UIElements.UxmlAttributeDescription;
public class UI_BGPanel : BasePanel
{
[HideInInspector]
public Button btn_h51, btn_h52;
TextMeshProUGUI text1, text2, text3;
public FFmpegPlayerBasicRawImage mediaPlayer1;
public FFmpegPlayerBasicRawImage mediaPlayer2;
public FFmpegPlayerBasicRawImage mediaPlayer3;
public FFmpegPlayerBasicRawImage mediaPlayer4;
public FFmpegPlayerBasicRawImage mediaPlayerHW;
public FFmpegPlayerBasicRawImage mediaPlayerZW;
public CanvasWebViewPrefab webViewPrefabZW;
private LiveUrlData liveUrlData;
public RTSPUrlInfo rtspUrlInfo = new RTSPUrlInfo();
string liveurl1;
protected override void Awake()
{
base.Awake();
FFmpegPlayerMono.Init(Application.streamingAssetsPath + "/FFmpegNativeLib");
btn_h51 = GetControl<Button>("btn_h51");
btn_h52 = GetControl<Button>("btn_h52");
text1 = GetControl<TextMeshProUGUI>("text1");
text2 = GetControl<TextMeshProUGUI>("text2");
text3 = GetControl<TextMeshProUGUI>("text3");
var filePath = Path.Combine(Application.streamingAssetsPath, "StateTrendConfig/LiveUrl.json");
if (File.Exists(filePath))
{
var jsonStr = File.ReadAllText(filePath);
var config = JsonConvert.DeserializeObject<LiveUrlData>(jsonStr);
liveUrlData = config;
}
else
{
Debug.Log("LiveUrl.json not found");
}
}
protected override void OnClick(string controlName)
{
base.OnClick(controlName);
switch (controlName)
{
case "btn_h51":
WebViewController.Instance.canvash51Prefab.gameObject.SetActive(true);
WebViewController.Instance.canvash52Prefab.gameObject.SetActive(false);
break;
case "btn_h52":
WebViewController.Instance.canvash51Prefab.gameObject.SetActive(false);
WebViewController.Instance.canvash52Prefab.gameObject.SetActive(true);
break;
default:
break;
}
}
void Start()
{
//if (liveUrlData != null) OnLoadVideo();
//OnLoadZWVideo();
}
private void OnLoadVideo()
{
/*var filePath = Path.Combine(Application.streamingAssetsPath, "StateTrendConfig/RTSPUrlInfo.json");
if (File.Exists(filePath))
{
var jsonStr = File.ReadAllText(filePath);
var config = JsonConvert.DeserializeObject<RTSPUrlInfo>(jsonStr);
rtspUrlInfo = config;
liveurl1 = "rtsp://" + rtspUrlInfo.Username + ":" + rtspUrlInfo.Password + "@" + rtspUrlInfo.IP + ":" + rtspUrlInfo.Port + "/cam/realmonitor?channel=19&subtype=0&proto=Private3";
mediaPlayer1.UseTcp = true;
mediaPlayer1.OpenPlayUrl(liveurl1);
}
else
{
Debug.Log("RTSPUrlInfo.json not found");
}*/
#region <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɨ<EFBFBD><EFBFBD>
if (liveUrlData.LiveUrl1.Contains("rtsp"))
{
mediaPlayer1.UseTcp = true;
mediaPlayer1.OpenPlayUrl(liveUrlData.LiveUrl1);
}
else
{
mediaPlayer1.UseTcp = true;
mediaPlayer1.OpenPlayUrl(Application.streamingAssetsPath + liveUrlData.LiveUrl1);
}
if (liveUrlData.LiveUrl2.Contains("rtsp"))
{
mediaPlayer2.UseTcp = true;
mediaPlayer2.OpenPlayUrl(liveUrlData.LiveUrl2);
}
else
{
mediaPlayer2.UseTcp = true;
mediaPlayer2.OpenPlayUrl(Application.streamingAssetsPath + liveUrlData.LiveUrl2);
}
if (liveUrlData.LiveUrl3.Contains("rtsp"))
{
mediaPlayer3.UseTcp = true;
mediaPlayer3.OpenPlayUrl(liveUrlData.LiveUrl3);
}
else
{
mediaPlayer3.UseTcp = true;
mediaPlayer3.OpenPlayUrl(Application.streamingAssetsPath + liveUrlData.LiveUrl3);
}
if (liveUrlData.LiveUrl4.Contains("rtsp"))
{
mediaPlayer4.UseTcp = true;
mediaPlayer4.OpenPlayUrl(liveUrlData.LiveUrl4);
}
else
{
mediaPlayer4.UseTcp = true;
mediaPlayer4.OpenPlayUrl(Application.streamingAssetsPath + liveUrlData.LiveUrl4);
}
#endregion
#region <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (liveUrlData.LiveUrlHW.Contains("rtsp"))
{
mediaPlayerHW.UseTcp = true;
mediaPlayerHW.OpenPlayUrl(liveUrlData.LiveUrlHW);
}
else
{
mediaPlayerHW.UseTcp = true;
mediaPlayerHW.OpenPlayUrl(Application.streamingAssetsPath + liveUrlData.LiveUrlHW);
}
#endregion
#region <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (liveUrlData.LiveUrlZW.Contains("rtsp"))
{
mediaPlayerZW.UseTcp = true;
mediaPlayerZW.OpenPlayUrl(liveUrlData.LiveUrlZW);
}
else
{
mediaPlayerZW.UseTcp = true;
mediaPlayerZW.OpenPlayUrl(Application.streamingAssetsPath + liveUrlData.LiveUrlZW);
}
#endregion
}
/// <summary>
/// <20><><EFBFBD>س<EFBFBD><D8B3><EFBFBD>ɨ<EFBFBD><C9A8><EFBFBD><EFBFBD>Ƶ
/// </summary>
public void OnLoadCSVideo()
{
if (liveUrlData == null) return;
if (liveUrlData.LiveUrl1.Contains("rtsp"))
{
mediaPlayer1.gameObject.SetActive(true); text1.gameObject.SetActive(false);
mediaPlayer1.UseTcp = true;
mediaPlayer1.OpenPlayUrl(liveUrlData.LiveUrl1);
}
else
{
mediaPlayer1.gameObject.SetActive(true); text1.gameObject.SetActive(false);
mediaPlayer1.UseTcp = true;
mediaPlayer1.OpenPlayUrl(Application.streamingAssetsPath + liveUrlData.LiveUrl1);
}
if (liveUrlData.LiveUrl2.Contains("rtsp"))
{
mediaPlayer2.gameObject.SetActive(true); text1.gameObject.SetActive(false);
mediaPlayer2.UseTcp = true;
mediaPlayer2.OpenPlayUrl(liveUrlData.LiveUrl2);
}
else
{
mediaPlayer2.gameObject.SetActive(true); text1.gameObject.SetActive(false);
mediaPlayer2.UseTcp = true;
mediaPlayer2.OpenPlayUrl(Application.streamingAssetsPath + liveUrlData.LiveUrl2);
}
if (liveUrlData.LiveUrl3.Contains("rtsp"))
{
mediaPlayer3.gameObject.SetActive(true); text1.gameObject.SetActive(false);
mediaPlayer3.UseTcp = true;
mediaPlayer3.OpenPlayUrl(liveUrlData.LiveUrl3);
}
else
{
mediaPlayer3.gameObject.SetActive(true); text1.gameObject.SetActive(false);
mediaPlayer3.UseTcp = true;
mediaPlayer3.OpenPlayUrl(Application.streamingAssetsPath + liveUrlData.LiveUrl3);
}
if (liveUrlData.LiveUrl4.Contains("rtsp"))
{
mediaPlayer4.gameObject.SetActive(true); text1.gameObject.SetActive(false);
mediaPlayer4.UseTcp = true;
mediaPlayer4.OpenPlayUrl(liveUrlData.LiveUrl4);
}
else
{
mediaPlayer4.gameObject.SetActive(true); text1.gameObject.SetActive(false);
mediaPlayer4.UseTcp = true;
mediaPlayer4.OpenPlayUrl(Application.streamingAssetsPath + liveUrlData.LiveUrl4);
}
}
/// <summary>
/// <20><><EFBFBD>غ<EFBFBD><D8BA><EFBFBD><EFBFBD><EFBFBD>Ƶ
/// </summary>
public void OnLoadHWVideo()
{
if (liveUrlData == null) return;
if (liveUrlData.LiveUrlHW.Contains("rtsp"))
{
mediaPlayerHW.gameObject.SetActive(true); text2.gameObject.SetActive(false);
mediaPlayerHW.UseTcp = true;
mediaPlayerHW.OpenPlayUrl(liveUrlData.LiveUrlHW);
}
else
{
mediaPlayerHW.gameObject.SetActive(true); text2.gameObject.SetActive(false);
mediaPlayerHW.UseTcp = true;
mediaPlayerHW.OpenPlayUrl(Application.streamingAssetsPath + liveUrlData.LiveUrlHW);
}
}
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ
/// </summary>
public void OnLoadZWVideo()
{
if (liveUrlData == null) return;
if (liveUrlData.LiveUrlZW.Contains("rtsp"))
{
mediaPlayerZW.gameObject.SetActive(true); text3.gameObject.SetActive(false);
mediaPlayerZW.UseTcp = true;
mediaPlayerZW.OpenPlayUrl(liveUrlData.LiveUrlZW);
}
else if(liveUrlData.LiveUrlZW.Contains("mp4"))
{
mediaPlayerZW.gameObject.SetActive(true); text3.gameObject.SetActive(false);
mediaPlayerZW.UseTcp = true;
mediaPlayerZW.OpenPlayUrl(Application.streamingAssetsPath + liveUrlData.LiveUrlZW);
}
else if (liveUrlData.LiveUrlZW.Contains("html"))
{
webViewPrefabZW.gameObject.SetActive(true); text3.gameObject.SetActive(false);
webViewPrefabZW.InitialUrl = liveUrlData.LiveUrlZW;
}
}
}
/// <summary>
/// rtsp<73><70>ַ
/// </summary>
public class LiveUrlData
{
[JsonProperty("liveUrl1")]
public string LiveUrl1 { get; set; }
[JsonProperty("liveUrl2")]
public string LiveUrl2 { get; set; }
[JsonProperty("liveUrl3")]
public string LiveUrl3 { get; set; }
[JsonProperty("liveUrl4")]
public string LiveUrl4 { get; set; }
[JsonProperty("liveUrHW")]
public string LiveUrlHW { get; set; }
[JsonProperty("liveUrZW")]
public string LiveUrlZW { get; set; }
}
public class RTSPUrlInfo
{
[JsonProperty("username")]
public string Username { get; set; }
[JsonProperty("passward")]
public string Password { get; set; }
[JsonProperty("ip")]
public string IP { get; set; }
[JsonProperty("port")]
public string Port { get; set; }
}
public class Config
{
[JsonProperty("playBack")]
public string PlayBack { get; set; }
[JsonProperty("waitingTime")]
public int WaitingTime { get; set; }
[JsonProperty("dgpwaitingTime")]
public int DgpwaitingTime { get; set; }
[JsonProperty("swwaitingTime")]
public int SwwaitingTime { get; set; }
}