-1

我想在我的 mobilefirst 混合页面上放置一个 Android 原生 videoview

我查看了下面的这个链接,这对将本机视图放在混合 html 页面上方没有帮助。(有创建本地活动的示例,但这里不是这种情况)

https://developer.ibm.com/mobilefirstplatform/documentation/getting-started-7-0/adding-native-functionality/

我找到了一种解决方法及其工作,但我想要一个适当的解决方案

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);
					
		}
 		
	}

4

1 回答 1

-1

是什么让您认为这是一种解决方法而不是正确的解决方案?这不是mobilefirst应该给你的东西;如果你让它工作,那很好。你有解决方案。

也就是说,您仍然应该看看这些教程:

于 2016-01-12T12:22:19.583 回答