UIKIT 集成
根据文档粘贴 、复制,页面听到声音,却一直再转圈。解决:
//设置加载需要显示的view
mEZUIPlayer.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创建
<SurfaceView
android: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:
@Override
public void surfaceCreated(@NonNull SurfaceHolder holder) {
if (player != null) {
player.setSurfaceHold(holder);
Log.d("surface","创建");
}
mRealPlaySh = holder;
player.startRealPlay();
}
@Override
public void surfaceChanged(@NonNull SurfaceHolder holder, int format, int width, int height) {
if (player != null) {
player.setSurfaceHold(holder);
}
mRealPlaySh = holder;
}
@Override
public void surfaceDestroyed(@NonNull SurfaceHolder holder) {
}
实现 Handler.Callback:
@Override
public 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;
}
webview 通过js 调用 java
//WebView启用Javascript脚本执行
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.addJavascriptInterface(MainActivity.this,"android");
@JavascriptInterface
public 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 :"8a2e6bd438ddfa45b255",
accessToken : "at.4kjmmmau"
}
// 与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')");