我想告訴你在Android的低版本和更高版本管視頻。我的代碼工作正常到Android 3.0但4.0上顯示你管視頻屏幕,但是當點擊播放它只顯示你管視頻上的進度條。webview不顯示你管視頻上的Android 4.0(ICS)
這裏是我的代碼 -
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();
}
你爲什麼使用webview? (https://developers.google.com/youtube/android/player/) – Budius
@budius,哪些是其他選項? –
我發佈的鏈接! – Budius