我有一个使用WebView显示网页的活动。在该页面中,有一个指向YouTube视频的链接(因此它不是我可以或需要嵌入的视频)。
问题是视频无法播放 - 我可以通过点击图标看到视频预览图像,但点击它没有响应。有什么可以做的吗?
public class DisplayWebPage extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.display_web_page);
Bundle extras = getIntent().getExtras();
String url = extras.getString("url");
WebView webview = (WebView)findViewById(R.id.WebView1);
webview.setWebViewClient(new WebViewClient());
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl(url);
}
}
答案 0 :(得分:5)
public class MyPdfViewActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
WebView mWebView=new WebView(MyPdfViewActivity.this);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setPluginsEnabled(true);
mWebView.loadUrl(youtube_link);
setContentView(mWebView);
}
}
<强>更新:: 强> 如果上述方法不起作用,请尝试以下::
public class main extends Activity {
/** Called when the activity is first created. */
@ Override
public void onCreate (Bundle savedInstanceState) {
super. onCreate (savedInstanceState);
setContentView (R.layout.main);
WebView web = (WebView) findViewById (R.id.webView);
web. getSettings().setJavaScriptEnabled (true);
web. getSettings().setJavaScriptCanOpenWindowsAutomatically (false);
web. getSettings().setPluginsEnabled (true);
web. getSettings().setSupportMultipleWindows (false);
web. getSettings().setSupportZoom (false);
web. setVerticalScrollBarEnabled (false);
web. setHorizontalScrollBarEnabled (false);
web. loadUrl ("THE URL TO YOUR WEBVIEW SITE SHOULD GO HERE");
web. setWebViewClient (new WebViewClient () {
@ Override public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.startsWith("vnd.youtube")){
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
return true;
}
else
{
return false;
}
}
});
}
}