我想在我的 mobilefirst 混合页面上放置一个 Android 原生 videoview
我查看了下面的这个链接,这对将本机视图放在混合 html 页面上方没有帮助。(有创建本地活动的示例,但这里不是这种情况)
我找到了一种解决方法及其工作,但我想要一个适当的解决方案
public void onInitWebFrameworkComplete(WLInitWebFrameworkResult result){
if (result.getStatusCode() == WLInitWebFrameworkResult.SUCCESS) {
super.loadUrl(WL.getInstance().getMainHtmlFilePath());
video1 = new VideoView(this);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(300,300); //The WRAP_CONTENT parameters can be replaced by an absolute width and height or the FILL_PARENT option)
params.leftMargin = 100; //Your X coordinate
params.topMargin = 100; //Your Y coordinate
super.addContentView(video1, params);
video1.setVisibility(View.GONE);
} else {
handleWebFrameworkInitFailure(result);
}
}
private void handleWebFrameworkInitFailure(WLInitWebFrameworkResult result){
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
alertDialogBuilder.setNegativeButton(R.string.close, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which){
finish();
}
});
alertDialogBuilder.setTitle(R.string.error);
alertDialogBuilder.setMessage(result.getMessage());
alertDialogBuilder.setCancelable(false).create().show();
}
@Override
public void onActionReceived(String action, JSONObject data) {
Log.d("TEST","********AM NATIVE**********");
if (action.equals("start_video"))
{
Log.d("TEST","********starting Video**********");
getActivity().runOnUiThread(new Runnable() {
public void run()
{
video1.setVisibility(View.VISIBLE);
Uri uri=Uri.parse("/sdcard/a.mp4");
video1.setVideoURI(uri);
video1.start();
Log.d("TEST","Inside Thread");
}
});
} else if (action.equals("stop_video")){
Log.d("TEST","********Stop Video**********");
video1.stopPlayback();
video1.setVisibility(View.GONE);
}
}