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

133 lines
4.0 KiB
C#
Raw Blame History

using Hanatric.Unity.Video.FFmpegPlayer;
using Newtonsoft.Json;
using System.IO;
using UnityEngine;
using UnityEngine.UI;
using Vuplex.WebView;
public class UI_BGPanel : BasePanel
{
[HideInInspector]
public static Button btn_h51, btn_h52;
public FFmpegPlayerBasicRawImage mediaPlayer1;
public FFmpegPlayerBasicRawImage mediaPlayer2;
public FFmpegPlayerBasicRawImage mediaPlayer3;
public FFmpegPlayerBasicRawImage mediaPlayer4;
public FFmpegPlayerBasicRawImage mediaPlayerHW;
public FFmpegPlayerBasicRawImage mediaPlayerZW;
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");
btn_h51.onClick.AddListener(() =>
{
WebViewController.Instance.canvash51Prefab.gameObject.SetActive(true);
WebViewController.Instance.canvash52Prefab.gameObject.SetActive(false);
//WebViewController.Instance.canvash51Prefab.
});
btn_h52.onClick.AddListener(() =>
{
WebViewController.Instance.canvash51Prefab.gameObject.SetActive(false);
WebViewController.Instance.canvash52Prefab.gameObject.SetActive(true);
}
);
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");
}
}
void Start()
{
if (liveUrlData!=null) OnLoadVideo();
}
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");
}
//mediaPlayer1.UseTcp = true;
//mediaPlayer1.OpenPlayUrl(liveurl1);
mediaPlayer2.UseTcp = true;
mediaPlayer2.OpenPlayUrl(liveUrlData.LiveUrl2);
mediaPlayer3.UseTcp = true;
mediaPlayer3.OpenPlayUrl(liveUrlData.LiveUrl3);
mediaPlayer4.UseTcp = true;
mediaPlayer4.OpenPlayUrl(liveUrlData.LiveUrl4);
mediaPlayerHW.UseTcp = true;
mediaPlayerHW.OpenPlayUrl(liveUrlData.LiveUrlHW);
mediaPlayerZW.UseTcp = true;
mediaPlayerZW.OpenPlayUrl(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; }
}