| | |
| | | using Com.Lechange.Opensdk.Media; |
| | | using HDL_ON.DAL.Server; |
| | | using HDL_ON_Android.LeChengView.Form; |
| | | using Java.IO; |
| | | using Java.Lang; |
| | | |
| | | namespace HDL_ON_Android |
| | |
| | | { |
| | | private static LeChengVideoActivity CurtActivity; |
| | | // |
| | | private string URL = "openapi.easy4ip.com:443"; |
| | | private string URL = "openapi.easy4ip.com:443"; //海外(正式) |
| | | private static string URL_LC_CHINA = "openapi.lechange.cn:443"; //中国大陆(正式) |
| | | private static string URL_LC_Overseas = "openapi.easy4ip.com:443"; //中国大陆(正式) |
| | | public string AccessToken = ""; |
| | | public string DeviceId = ""; |
| | | public string Psk = ""; |
| | | public string PlayToken = "";//播放playToken |
| | | public string CallId = "";//呼叫Id |
| | | private int Type = 0;//0监控,1对讲 |
| | | private string DeviceName = "";// 备注 |
| | | |
| | | /// <summary> |
| | | /// 0:国内,1海外 |
| | | /// </summary> |
| | |
| | | Type = Intent.GetIntExtra("Type", 0);//0监控,1对讲//1 |
| | | Location = Intent.GetIntExtra("Location", 0);//1 |
| | | CallId = Intent.GetStringExtra("callId");//1384766990812426242 |
| | | DeviceName = Intent.GetStringExtra("DeviceName"); |
| | | |
| | | InitLCSDK(); |
| | | |
| | |
| | | ivBack = (ImageView)FindViewById(Resource.Id.videoBackImg); |
| | | tvName = (TextView)FindViewById(Resource.Id.nameText); |
| | | |
| | | tvName.SetText("DeviceName", null); |
| | | tvName.SetText(DeviceName, null); |
| | | ivBack.SetOnClickListener(this); |
| | | |
| | | } |
| | |
| | | mPlayWindow = new LCOpenSDK_PlayWindow(); |
| | | mPlayWindow.InitPlayWindow(this, flWindowContent, 0, true); |
| | | |
| | | if (Location == 1) |
| | | URL = "openapi.easy4ip.com:443"; |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// </summary> |
| | | private void InitLCSDK() |
| | | { |
| | | |
| | | if (Location == 1) |
| | | { |
| | | URL = URL_LC_Overseas; |
| | | }else { |
| | | URL = URL_LC_CHINA; |
| | | } |
| | | |
| | | InitParams initParams = new InitParams(this, URL, AccessToken); |
| | | LCOpenSDK_Api.InitOpenApi(initParams); |
| | | } |
| | |
| | | try |
| | | { |
| | | LCOpenSDK_ParamReal paramReal = new LCOpenSDK_ParamReal(AccessToken, DeviceId, 0, Psk, PlayToken, 1, false, true); |
| | | //PlayEventListener listener = new PlayEventListener();//实现播放事件监听回调 2021-10-15 目前不能监听,监听了会空异常 |
| | | //mPlayWindow.WindowListener = listener;//实现播放事件监听回调 |
| | | mPlayWindow.PlayRtspReal(paramReal); |
| | | } |
| | | catch (System.Exception e) |
| | |
| | | public void Stop() |
| | | { |
| | | mPlayWindow.StopRtspReal(true);//关闭视频 |
| | | //mPlayWindow.WindowListener = null; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | { |
| | | CloseAudio();// 关闭Audio |
| | | LCOpenSDK_Talk.Listener = new AudioTalkerListener();//设置对讲监听 |
| | | //2021-10-29 对讲请求类型,call呼叫,如果不传,默认为talk |
| | | string talkType = "talk"; |
| | | if (Type == 1)//0监控,1对讲 |
| | | { |
| | | talkType = "call"; |
| | | } |
| | | // 对讲参数 |
| | | LCOpenSDK_ParamTalk paramTalk = new LCOpenSDK_ParamTalk(AccessToken, DeviceId, -1, Psk, PlayToken, true); |
| | | LCOpenSDK_ParamTalk paramTalk = new LCOpenSDK_ParamTalk(AccessToken, DeviceId, -1, Psk, PlayToken, true, talkType); |
| | | LCOpenSDK_Talk.PlayTalk(paramTalk); |
| | | } |
| | | |
| | |
| | | public bool CloseAudio() |
| | | { |
| | | return mPlayWindow.StopAudio() == 0; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 开锁 |
| | | /// </summary> |
| | | public void Unlock() |
| | | { |
| | | // |
| | | Dictionary<string, object> dic = new Dictionary<string, object>(); |
| | | dic.Add("deviceId", this.DeviceId); |
| | | dic.Add("callId", this.CallId); |
| | | |
| | | var requestJson = HttpUtil.GetSignRequestJson(dic); |
| | | var revertObj = HttpUtil.RequestHttpsPostFroHome("/home-wisdom/platform/imou/openDoorbell", requestJson); |
| | | if (revertObj.Code == StateCode.SUCCESS) |
| | | { |
| | | Toast.MakeText(this, Resources.GetString(Resource.String.unlock_success), ToastLength.Short).Show(); |
| | | } |
| | | else |
| | | { |
| | | Toast.MakeText(this, Resources.GetString(Resource.String.unlock_fail), ToastLength.Short).Show(); |
| | | } |
| | | } |
| | | |
| | | ///// <summary> |
| | | ///// 发送广播,通知刷新图库的显示 |
| | | ///// </summary> |
| | | ///// <param name="path"></param> |
| | | //void SendBroadcastScanFile(Context context, string path) |
| | | //{ |
| | | // // 发送广播,通知刷新图库的显示 |
| | | // Intent scanIntent = new Intent(Intent.ActionMediaScannerScanFile); |
| | | // scanIntent.SetData(Android.Net.Uri.FromFile(new File(path))); |
| | | // context.SendBroadcast(scanIntent); |
| | | //} |
| | | |
| | | /// <summary> |
| | | /// 截图 |
| | | /// </summary> |
| | | /// <param name="path"></param> |
| | | public void SnapShot(string path) |
| | | { |
| | | try |
| | | { |
| | | int code = mPlayWindow.SnapShot(path); |
| | | if (code == 0) |
| | | { |
| | | //2021-09-01 增加发送广播,通知刷新图库的显示 |
| | | HDLONUtils.SendBroadcastScanFile(this, path); |
| | | |
| | | //Android.Provider.MediaStore.Images.Media.InsertImage(this.getContentResolver(), path, "ss", "ss"); |
| | | Toast.MakeText(this, Resources.GetString(Resource.String.screenshot_success), ToastLength.Short).Show(); |
| | | } |
| | | else |
| | | { |
| | | Toast.MakeText(this, Resources.GetString(Resource.String.screenshot_fail), ToastLength.Short).Show(); |
| | | } |
| | | } |
| | | catch (System.Exception e) |
| | | { |
| | | string error = e.Message; |
| | | } |
| | | |
| | | //运行到这,photoFile已经存在,这里需要获得这个文件的uri |
| | | //* 分两种情况,android7.0以上和以下 |
| | | // 先存入临时目录,然后再移动到相册目录中 |
| | | //File photoFile = new File(path); |
| | | //Android.Net.Uri photoUri; |
| | | |
| | | //if (Build.VERSION.SdkInt >= 24) |
| | | //if (Build.VERSION.PreviewSdkInt >= 24) |
| | | //{ |
| | | |
| | | // /** |
| | | // * FileProvider.getUriForFile(),这个方法中需要填写三个参数, |
| | | // * 第一个Context, |
| | | // * 第二个S |
| | | // * tring 任意 |
| | | // * 第三个File |
| | | // */ |
| | | // photoUri = FileProvider.GetUriForFile(this, "HDL Video SnapShot", photoFile); |
| | | |
| | | //} |
| | | //else |
| | | //{ |
| | | // photoUri = Android.Net.Uri.FromFile(photoFile); |
| | | //} |
| | | |
| | | } |
| | | |
| | | private ContentResolver getContentResolver() |
| | | { |
| | | throw new NotImplementedException(); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | |
| | | try |
| | | { |
| | | System.Console.WriteLine("LC OnTalkResult error:" + error + " type:" + type); |
| | | bool talkResult = false; |
| | | if (type == 99 || error.Equals("-1000") || error.Equals("0") || error.Equals("1") || error.Equals("3")) |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 播放、预览结果回调 |
| | | /// resultSource: 0--RTSP 1--HLS 5--DHHTTP 99--OPENAPI |
| | | /// </summary> |
| | | class PlayEventListener : LCOpenSDK_EventListener |
| | | { |
| | | public override void OnPlayerResult(int index, string code, int resultSource) |
| | | { |
| | | base.OnPlayerResult(index, code, resultSource); |
| | | System.Console.WriteLine("LC OnPlayerResult index:" + index + " code:" + code + " resultSource:"+ resultSource); |
| | | } |
| | | |
| | | |
| | | } |
| | | } |
| | | } |