アンドロイドの下位バージョンと上位バージョンの両方でチューブビデオを表示したいのですが、私のコードはアンドロイド3.0までは正常に機能しますが、4.0ではチューブビデオ画面が表示されますが、クリックして再生すると、チューブビデオのプログレスバーのみが表示されます。
これが私のコードです-
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
{
playVideoForBelowVersion();
}
else
{
playVideoForIcs();
}
private void playVideoForBelowVersion()
{
String url = videoLinks[position] + "?autoplay=1";
webView.getSettings().setJavaScriptEnabled(true);
webView. getSettings().setJavaScriptCanOpenWindowsAutomatically (false);
webView. getSettings().setPluginsEnabled (true);
webView. getSettings().setSupportMultipleWindows (false);
webView. getSettings().setSupportZoom (false);
webView. setVerticalScrollBarEnabled (false);
webView. setHorizontalScrollBarEnabled (false);
webView.loadUrl(url);
webView.setWebChromeClient(new WebChromeClient());
webView.setWebViewClient(new WebViewClient()
{
@Override
public void onPageFinished(WebView view, String url) {
// TODO Auto-generated method stub
super.onPageFinished(view, url);
// progressDialog.dismiss();
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
// TODO Auto-generated method stub
super.onPageStarted(view, url, favicon);
/*progressDialog.setMessage("Loading Video please wait...");
progressDialog.show();*/
}
@Override
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) {
// TODO Auto-generated method stub
super.onReceivedError(view, errorCode, description, failingUrl);
Utilities.showToast(FullVideoAct.this, "Video Error...");
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
view.loadUrl(url);
return true;
}
});
webView.requestFocus();
}
private void playVideoForIcs()
{
getWindow().setFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
String strUrl = "http://m.youtube.com/index?&desktop_uri=%2F#/watch?v="+videoLinksIds[position];
// String strUrl = videoLinks[position] + "?autoplay=1";
// String strUrl ="http://www.youtube.com/v/"+videoLinksIds[position]+"?enablejsapi=1&version=3&playerapiid=ytplayer";
webView.getSettings().setJavaScriptEnabled(true);
webView. getSettings().setJavaScriptCanOpenWindowsAutomatically (false);
webView. getSettings().setPluginsEnabled (true);
webView. getSettings().setSupportMultipleWindows (false);
webView. getSettings().setSupportZoom (false);
webView. setVerticalScrollBarEnabled (false);
webView. setHorizontalScrollBarEnabled (false);
webView.loadUrl(strUrl);
//wvVideo.loadData(htmlString, "text/html", "UTF-8");
webView.setWebChromeClient(new WebChromeClient());
webView.requestFocus();
}