/// <summary> /// 获取监控列表 /// </summary> /// <returns></returns> public static List <CameraInfo> GetCameraList() { var _list = new List <CameraInfo>(); var _page = 0; var _limit = 500; try { while (true) { IntPtr _hander; int _len; if (YsSDK.OpenSDK_Data_GetDevList(AccessToken, _page++, _limit, out _hander, out _len) == 0) { var _response = Marshal.PtrToStringAnsi(_hander); var _result = _response.FromJson <CameraListResponse>(); _list.AddRange(_result?.CameraList); if (_result.Count < _limit) { break; } } } } catch (Exception ex) { LogService.AppendErrorLog(typeof(YsAction), "获取设备列表异常", ex); } return(_list); }
/// <summary> /// 分配会话 /// </summary> /// <returns></returns> public static IntPtr AllocSession() { IntPtr userID = Marshal.StringToHGlobalAnsi(Cfg.UserId); bool flag = YsSDK.OpenSDK_AllocSession(callBack, userID, ref SessionId, ref SessionIdLth, false, uint.MaxValue) == 0; SessionIdstr = Marshal.PtrToStringAnsi(SessionId, SessionIdLth); return(SessionId); }
/// <summary> /// 获取监控列表 /// </summary> /// <param name="deviceSerial"></param> /// <returns></returns> public static List <CameraInfo> GetCameraList(string deviceSerial) { var _list = new List <CameraInfo>(); try { IntPtr _hander; int _len; if (YsSDK.OpenSDK_Data_GetDeviceInfo(AccessToken, deviceSerial, out _hander, out _len) == 0) { var _response = Marshal.PtrToStringAnsi(_hander); var _result = _response.FromJson <ResponseResult <SingleDeviceCameraListResponse> >(); _list.AddRange(_result?.Result?.Data); } } catch (Exception ex) { LogService.AppendErrorLog(typeof(YsAction), $"获取设备[deviceSerial={deviceSerial}]列表异常", ex); } return(_list); }
/// <summary> /// 获取accesstoken /// </summary> /// <returns></returns> public static string GetAccessToken() { IntPtr iMessage; int iLength; string _cmd = GetCommond("token"); if (YsSDK.OpenSDK_HttpSendWithWait(Cfg.ApiUrl, _cmd, "", out iMessage, out iLength) == 0) { var _rmsg = Marshal.PtrToStringAnsi(iMessage); var _result = _rmsg.FromJson <ResponseResult <TokenResponse> >(); if (_result.Result.IsSuccess) { Cfg.AccessToken = _result.Result.Data.AccessToken; Debug.WriteLine(Cfg.AccessToken); } else { Debug.WriteLine(_result.Result.ErrorMsg); } } return(Cfg.AccessToken); }
/// <summary> /// 释放Skd /// </summary> /// <returns></returns> public static bool DisposeSdk() { return(YsSDK.OpenSDK_FiniLib() == 0); }
/// <summary> /// 初始化SDK /// </summary> /// <returns></returns> public static bool InitSdk() { return(YsSDK.OpenSDK_InitLib(Cfg.AuthAddr, Cfg.PlatformAddr, Cfg.AppKey) == 0); }
/// <summary> /// 结束会话 /// </summary> /// <param name="sessionId"></param> static bool CloseAllocion(IntPtr sessionId) { return(YsSDK.OpenSDK_FreeSession(sessionId.ToString()) == 0); }
/// <summary> /// 播放视频(预览) /// </summary> /// <param name="playWnd"></param> /// <param name="sessionId"></param> /// <param name="cameraId"></param> /// <param name="level">清晰度,0流畅,1标清,2高清</param> /// <param name="safeKey">安全码</param> /// <returns></returns> public static bool Play(IntPtr playWnd, IntPtr sessionId, string cameraId, int level = 2, string safeKey = "MAIKE100") { return(YsSDK.OpenSDK_StartRealPlay(SessionId, playWnd, cameraId, AccessToken, level, safeKey, Cfg.AppKey, 0) == 0); }
/// <summary> /// 停止播放(预览) /// </summary> /// <param name="SessionId"></param> /// <returns></returns> public static bool Stop(IntPtr SessionId) { CloseAllocion(SessionId); //每次播放结束会话 return(YsSDK.OpenSDK_StopRealPlay(SessionId, 0) == 0); }