我有一个工作解决方案来查看Android手机中的HTML5视频。它在Android平板电脑上根本不起作用(例如三星galaxy tab 2)。当我启动视频时,我可以听到音频,但屏幕是黑色的。
这是我的代码:http://pastebin.com/P9ebDKha
我是否必须重写所有代码?小错误?
答案 0 :(得分:0)
这就是我如何播放填充了我所拥有的webview大小的YouTube视频...
video = (WebView) v.findViewById(R.id.videoview);
String videoURL = "http://www.youtube.com/v/DZi6DEJsOJ0?fs=1&hl=nl_NL";
video.setHorizontalScrollBarEnabled(false);
video.setVerticalScrollBarEnabled(false);
video.getSettings().setJavaScriptEnabled(true);
video.getSettings().setPluginsEnabled(true);
Display display = getActivity().getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int widthdp = (int) (width / getResources().getDisplayMetrics().density);
int height = display.getHeight();
int heightdp = (int) (height / getResources().getDisplayMetrics().density);
String widthAndHeight = "width=" + widthdp + "height=" + heightdp;
String temp = "<object "
+ widthAndHeight
+ ">"
+ "<body style='margin:0;padding:0;'>"
+ "<param name='allowFullScreen' value='true'>"
+ "</param><param name='allowscriptaccess' value='always'>"
+ "</param><embed src='"
+ videoPoP
+ "'"
+ " type='application/x-shockwave-flash' style='margin:0;padding:0;' allowscriptaccess='always' allowfullscreen='true'"
+ widthAndHeight + "></embed></object>";
video.loadData(temp, "text/html", "utf-8");