134 lines
		
	
	
		
			4.7 KiB
		
	
	
	
		
			C#
		
	
	
	
			
		
		
	
	
			134 lines
		
	
	
		
			4.7 KiB
		
	
	
	
		
			C#
		
	
	
	
using BLL;
 | 
						|
using Newtonsoft.Json;
 | 
						|
using System;
 | 
						|
using System.Collections.Generic;
 | 
						|
using System.Configuration;
 | 
						|
using System.Linq;
 | 
						|
using System.Web;
 | 
						|
using System.Web.UI;
 | 
						|
using System.Web.UI.WebControls;
 | 
						|
 | 
						|
namespace FineUIPro.Web.Video
 | 
						|
{
 | 
						|
    public partial class Video : System.Web.UI.Page
 | 
						|
    {
 | 
						|
 | 
						|
        public string playIds
 | 
						|
        {
 | 
						|
            get
 | 
						|
            {
 | 
						|
                return (string)ViewState["playIds"];
 | 
						|
            }
 | 
						|
            set
 | 
						|
            {
 | 
						|
                ViewState["playIds"] = value;
 | 
						|
            }
 | 
						|
        }
 | 
						|
        protected void Page_Load(object sender, EventArgs e)
 | 
						|
        {
 | 
						|
            if (!IsPostBack)
 | 
						|
            {
 | 
						|
                this.playIds = "";
 | 
						|
                this.tvControlItem.Nodes.Clear();
 | 
						|
                TreeNode rootNode = new TreeNode();
 | 
						|
                rootNode.Text = "项目-设备";
 | 
						|
                rootNode.NodeID = "0";
 | 
						|
                rootNode.Expanded = true;
 | 
						|
                this.tvControlItem.Nodes.Add(rootNode);
 | 
						|
 | 
						|
                string url = ConfigurationManager.AppSettings["Video_URL"];
 | 
						|
                if (!string.IsNullOrEmpty(url))
 | 
						|
                {
 | 
						|
                    List<string> urls = new List<string>();
 | 
						|
                    string res = APIGetHttpService.Http(url + "api/v1/device/channeltree");
 | 
						|
 | 
						|
                    List<Dictionary<string, string>> jsonNvr = JsonConvert.DeserializeObject<List<Dictionary<string, string>>>(res);
 | 
						|
                    foreach (Dictionary<string, string> nvr in jsonNvr)
 | 
						|
                    {
 | 
						|
                        TreeNode newNode = new TreeNode();
 | 
						|
                        newNode.NodeID = nvr["id"];
 | 
						|
                        newNode.Text = nvr["customName"];
 | 
						|
                        newNode.ToolTip = "项目";
 | 
						|
                        newNode.Expanded = false;
 | 
						|
                        rootNode.Nodes.Add(newNode);
 | 
						|
                        string jsonCameras = APIGetHttpService.Http(url + "api/v1/device/channeltree?serial=" + nvr["serial"]);
 | 
						|
                        var data = JsonConvert.DeserializeObject<List<Dictionary<string, string>>>(jsonCameras);
 | 
						|
                        foreach (var video in data)
 | 
						|
                        {
 | 
						|
                            TreeNode tempNode = new TreeNode();
 | 
						|
                            tempNode.NodeID = video["id"];
 | 
						|
                            tempNode.Text = video["name"];
 | 
						|
                            tempNode.ToolTip = "设备";
 | 
						|
                            tempNode.EnableClickEvent = true;
 | 
						|
 | 
						|
                            newNode.Nodes.Add(tempNode);
 | 
						|
                        }
 | 
						|
                    }
 | 
						|
                }
 | 
						|
                else {
 | 
						|
 | 
						|
                    Alert.ShowInParent("请配置视频服务器地址!", MessageBoxIcon.Warning);
 | 
						|
                }
 | 
						|
            }
 | 
						|
        }
 | 
						|
        #region 树展开事件
 | 
						|
        /// <summary>
 | 
						|
        /// 树展开事件
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="sender"></param>
 | 
						|
        /// <param name="e"></param>
 | 
						|
        protected void tvControlItem_TreeNodeExpanded(object sender, TreeNodeEventArgs e)
 | 
						|
        { }
 | 
						|
        #endregion
 | 
						|
        #region 点击TreeView
 | 
						|
        /// <summary>
 | 
						|
        /// 点击TreeView
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="sender"></param>
 | 
						|
        /// <param name="e"></param>
 | 
						|
        protected void tvControlItem_NodeCommand(object sender, TreeCommandEventArgs e)
 | 
						|
        {
 | 
						|
            var id = this.tvControlItem.SelectedNodeID;
 | 
						|
            if (id.Contains(":"))
 | 
						|
            {
 | 
						|
                try
 | 
						|
                {
 | 
						|
                    string url = ConfigurationManager.AppSettings["Video_URL"];
 | 
						|
                    var stmp = new DateTimeOffset(DateTime.Now).ToUnixTimeSeconds() + "";
 | 
						|
                    string jsonCamera = APIGetHttpService.Http(url + "api/v1/stream/start?serial=" + id.Split(':')[0] + "&code=" + id.Split(':')[1] + "&_=" + stmp);
 | 
						|
                    var data = JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonCamera);
 | 
						|
 | 
						|
 | 
						|
 | 
						|
                    for (int i = 1; i <= 9; i++)
 | 
						|
                    {
 | 
						|
                        if (this.playIds.Contains("player0" + i))
 | 
						|
                        {
 | 
						|
                            continue;
 | 
						|
                        }
 | 
						|
                        else
 | 
						|
                        {
 | 
						|
                            this.playIds += "player0" + i;
 | 
						|
                            PageContext.RegisterStartupScript("play(\"" + "player0" + i + "\",\"" + data["HLS"] + "\")");
 | 
						|
                            break;
 | 
						|
                        }
 | 
						|
                    }
 | 
						|
                }
 | 
						|
                catch
 | 
						|
                {
 | 
						|
 | 
						|
                }
 | 
						|
            }
 | 
						|
        }
 | 
						|
        #endregion
 | 
						|
 | 
						|
 | 
						|
        protected void btnClose_Click(object sender, EventArgs e)
 | 
						|
        {
 | 
						|
            var id = Request.Form["__EVENTARGUMENT"];
 | 
						|
            this.playIds = this.playIds.Replace(id, "");
 | 
						|
            PageContext.RegisterStartupScript("play(\""  + id + "\",\"\")");
 | 
						|
 | 
						|
        }
 | 
						|
    }
 | 
						|
} |