Android 集成海康摄像头萤石平台坑
萤石文档
UIKIT 集成
根据文档粘贴 、复制,页面听到声音,却一直再转圈。解决:
//设置加载需要显示的viewmEZUIPlayer.setLoadingView(initProgressBar());
private View initProgressBar() {RelativeLayout relativeLayout = new RelativeLayout(this);relativeLayout.setBackgroundColor(Color.parseColor("#000000"));RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);relativeLayout.setLayoutParams(lp);RelativeLayout.LayoutParams rlp=new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);rlp.addRule(RelativeLayout.CENTER_IN_PARENT);//addRule参数对应RelativeLayout XML布局的属性ProgressBar mProgressBar = new ProgressBar(this);
// mProgressBar.setIndeterminateDrawable(getResources().getDrawable(R.drawable.progress));relativeLayout.addView(mProgressBar,rlp);return relativeLayout;}
Android SDK 集成
- 在layou xml创建
<SurfaceViewandroid:id="@+id/realplay_sv"android:layout_width="match_parent"android:layout_height="200"android:background="@android:color/transparent" />
- 设置 setSurfaceHold 、 Holder
mRealPlaySv = (SurfaceView) findViewById(R.id.realplay_sv);mRealPlaySh = mRealPlaySv.getHolder();mHandler = new Handler(this);player.setSurfaceHold(mRealPlaySh);mRealPlaySh.addCallback(this);
实现 SurfaceHolder.Callback:
@Overridepublic void surfaceCreated(@NonNull SurfaceHolder holder) {if (player != null) {player.setSurfaceHold(holder);Log.d("surface","创建");}mRealPlaySh = holder;player.startRealPlay();}@Overridepublic void surfaceChanged(@NonNull SurfaceHolder holder, int format, int width, int height) {if (player != null) {player.setSurfaceHold(holder);}mRealPlaySh = holder;}@Overridepublic void surfaceDestroyed(@NonNull SurfaceHolder holder) {}
实现 Handler.Callback:
@Overridepublic boolean handleMessage(Message msg) {switch (msg.what) {case EZConstants.EZRealPlayConstants.MSG_REALPLAY_PLAY_SUCCESS://播放成功break;case EZConstants.EZRealPlayConstants.MSG_REALPLAY_PLAY_FAIL://播放失败,得到失败信息ErrorInfo errorinfo = (ErrorInfo) msg.obj;//得到播放失败错误码int code = errorinfo.errorCode;//得到播放失败模块错误码String codeStr = errorinfo.moduleCode;//得到播放失败描述String description = errorinfo.description;//得到播放失败解决方方案String sulution = errorinfo.sulution;break;case EZConstants.MSG_VIDEO_SIZE_CHANGED://解析出视频画面分辨率回调try {String temp = (String) msg.obj;String[] strings = temp.split(":");int mVideoWidth = Integer.parseInt(strings[0]);int mVideoHeight = Integer.parseInt(strings[1]);//解析出视频分辨率} catch (Exception e) {e.printStackTrace();}break;default:break;}return false;}
Android webview 通过js 调用 java
//WebView启用Javascript脚本执行webView.getSettings().setJavaScriptEnabled(true);webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);webView.addJavascriptInterface(MainActivity.this,"android");
@JavascriptInterfacepublic void test(String gson) {// 将json字符串转对象AccountToken accountToken = new Gson().fromJson(gson,AccountToken.class);Log.d("js传参",accountToken.getAppKey());//启动播放页面Intent intent = new Intent(this, Activity.class);this.startActivity(intent);}
- js
function handleTest(){let param = {appKey :"5",accessToken : "at0-ghm4mmmau"}// 与java webView.addJavascriptInterface(MainActivity.this,"android"); 第二个参数一致android.test(JSON.stringify(param) )}
Android webview 通过java 调用 js
- js
function handleTest(){let param = {appKey :"5",accessToken : "at0-ghm4mmmau"}// 与java webView.addJavascriptInterface(MainActivity.this,"android"); 第二个参数一致android.test(JSON.stringify(param) )}
如果使用vue等打包,要把函数提升到 window 下;
window['handleTest'] = this.handleTest
- java 调用
mWebView.loadUrl("javascript:handleTest('dm')");
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
