184 lines
5.5 KiB
C#
184 lines
5.5 KiB
C#
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");
|
||
}*/
|
||
#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>
|
||
/// 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; }
|
||
}
|