我想在youtube上播放全屏视频,但我不能 一位用户向我发送了以下报告
java.lang.NullPointerException
at android.view.ViewGroup.addViewInner(ViewGroup.java:3377)
at android.view.ViewGroup.addView(ViewGroup.java:3249)
at android.view.ViewGroup.addView(ViewGroup.java:3225)
at android.webkit.HTML5VideoFullscreen.enterFullscreen(HTML5VideoFullscreen.java:253)
at android.webkit.HTML5VideoView.enterFullscreenVideoState(HTML5VideoView.java:527)
at android.webkit.HTML5VideoViewProxy$VideoPlayer.enterFullscreenVideo(HTML5VideoViewProxy.java:180)
at android.webkit.HTML5VideoViewProxy.handleMessage(HTML5VideoViewProxy.java:461)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4838)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608)
at dalvik.system.NativeStart.main(Native Method)
我使用的代码:
web.getSettings().setJavaScriptEnabled(true);
web.getSettings().setLoadWithOverviewMode(true);
web.getSettings().setUseWideViewPort(true);
web.getSettings().setBuiltInZoomControls(true);
web.getSettings().setPluginState(WebSettings.PluginState.ON);
web.setWebChromeClient(new WebChromeClient(){
@Override
public void onProgressChanged(WebView view, int newProgress) {
super.onProgressChanged(view, newProgress);
pgb.setProgress(newProgress);
}
@Override
public View getVideoLoadingProgressView() {
FrameLayout frameLayout = new FrameLayout(MainActivity.this);
frameLayout.setLayoutParams(new LayoutParams( LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
return frameLayout;
}
});
web.loadUrl("http://www.youtube.com");
我只是想让我明白该怎么做。
答案 0 :(得分:0)
我正在使用actionbarcompat因此我遵循此处的UI指南
webview_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</RelativeLayout>
Main.class
public class Main extends ActionBarActivity{
private WebView mWebView;
private String url;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.webview_layout);
url="http://example.com";
getSupportActionBar();
getSupportActionBar().setDisplayShowCustomEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setTitle("TITLE HERE");
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setBuiltInZoomControls(true);
mWebView.getSettings().setAppCacheMaxSize(1024*1024*8);
mWebView.getSettings().setAppCachePath(""+this.getCacheDir());
mWebView.getSettings().setAppCacheEnabled(true);
mWebView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
mWebView.loadUrl(url);
mWebView.setWebViewClient(new MyWebViewClient());
mWebView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
super.onProgressChanged(view, progress);
setSupportProgressBarIndeterminateVisibility((progress == 100)?false:true);
}
public void onReceivedTitle(WebView view, String title) {
super.onReceivedTitle(view, title);
CharSequence notavail = "Webpage not available";
}
});
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
mWebView.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
private class MyWebViewClient extends WebViewClient {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
}
请随意询问他们是否有任何不太清楚的事情。 谢谢希望它会帮助你,不要忘了投票