我有一些 WebView 代码,我正在尝试在 YouTube 频道上播放 YouTube 视频。但它所做的只是在视频上显示微调器图标,而从未真正开始播放视频。有人知道如何解决吗?
public class YoutubeActivity extends Activity
{
WebView webview = null;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
webview = new WebView(this);
webview.getSettings().setAppCacheEnabled(false);
webview.getSettings().setJavaScriptEnabled(true);
webview.setInitialScale(1);
webview.getSettings().setPluginState(PluginState.ON);
webview.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
WebSettings webSettings = webview.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setBuiltInZoomControls(true);
//webSettings.getMediaPlaybackRequiresUserGesture();
webSettings.setAllowContentAccess(true);
webSettings.setEnableSmoothTransition(true);
webSettings.setLoadsImagesAutomatically(true);
webSettings.setLoadWithOverviewMode(true);
webSettings.setSupportZoom(true);
webSettings.setUseWideViewPort(true);
setContentView(webview);
webview.loadUrl("http://www.youtube.com/g33ktalktv");
}
public void onBackPressed ( )
{
//Class.forName("com.***.HTML5WebView").getMethod("onPause", (Class[]) null).
//invoke(html5WebView, (Object[]) null);
webview.clearView();
}
@Override
public void onStop()
{
super.onStop();
// your code
webview.clearView();
}
}
这是清单设置:
<activity
android:name="YoutubeActivity"
android:label="Some string"
android:hardwareAccelerated="true"/>
提前致谢!