现在我在WebView中加载youtube视频。这在4.x及更高版本中运行良好,但我也希望为蜂窝设备实现。我不知道如何使用蜂窝状闪光灯播放youtube视频。请帮帮我。
这是我的代码。
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mContentView = (FrameLayout)findViewById(R.id.main_content);
mTargetView = (FrameLayout)findViewById(R.id.target_view);
myChromeClient = new MyChromeClient();
new Thread(new Runnable() {
@Override
public void run() {
video_view = (WebView)findViewById(R.id.webView);
if (savedInstanceState != null){
video_view.restoreState(savedInstanceState);
}
video_view.setWebViewClient(new WebViewClient());
video_view.getSettings().setJavaScriptEnabled(true);
video_view.getSettings().setPluginState(WebSettings.PluginState.ON);
video_view.setWebChromeClient(myChromeClient);
try {
video_view.loadDataWithBaseURL("", getHTML(), mimeType, encoding, "");
} catch (Exception e) {
e.printStackTrace();
Log.e("Status", "exception");
}
}
}).start();
}
public String getHTML() {
String html = "<iframe class=\"youtube-player\" style=\"border: 0; width: 100%; height: 95%; padding:0px; margin:0px\" id=\"ytplayer\" type=\"text/html\" src=\"http://www.youtube.com/embed/"
+ "bvraNCHUpuE"
+ "?fs=0\" frameborder=\"0\">\n"
+ "</iframe>\n";
return html;
}