我在WebView中打开一个网页。该网页包含一个iframe,其中包含嵌入的视频。我无法发布网页链接,因此发布其代码。
网页代码:
<html>
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" media="all" rel="stylesheet" type="text/css" />
<body>
<div id="here">
<div class="embed-responsive embed-responsive-16by9">
<iframe id="video" class="class="embed-responsive-item" src="https://player.vimeo.com/video/129955969?title=0&byline=0&portrait=0&color=f2f2ea&autoplay=1" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
</div
<p style="color:#167AD0;"><a href="#" >Algebra - Progressions</a></p>
<p style="color:#7E8394;">Bulls Eye Knowledge (P) Ltd.<br/>2 months ago * 1 views<br/></p>
<p style="border-top: 1px solid #7e8394;color: #7e8394;margin: 10px 0 0;padding: 0;"></p>
</div>
</body>
</html>
Android活动代码:
public class WebPlayerActivity extends Activity {
public static final String INTENT_EXTRA = "intent_extra";
public static final String INTENT_EXTRA_TITLE = "intent_extra_title";
private WebView webView;
@Override
public void onResume() {
super.onResume();
if (Build.VERSION.SDK_INT >= 11)
webView.onResume();
}
@Override
public void onPause() {
super.onPause();
if (Build.VERSION.SDK_INT >= 11)
webView.onPause();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_web_view);
TextView title = (TextView) findViewById(R.id.title);
ImageView back = (ImageView) findViewById(R.id.back);
webView = (WebView) findViewById(R.id.web_view);
title.setText(getIntent().getStringExtra(INTENT_EXTRA_TITLE));
back.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
webView.getSettings().setPluginState(WebSettings.PluginState.ON);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.setWebChromeClient(new WebChromeClient());
webView.loadUrl(getIntent().getStringExtra(INTENT_EXTRA));
}
@Override
protected void onDestroy() {
super.onDestroy();
webView.loadUrl("about:blank");
}
}
视图在开始时打开正常,但是当我点击播放时,有时它会让我在我的三星平板电脑(Android版本:4.2.2)中发生以下崩溃,有时音频运行正常,但视频是没有显示,只有黑屏。
崩溃:
java.lang.NullPointerException
at android.webkit.HTML5VideoView.reprepareData(HTML5VideoView.java:346)
at android.webkit.HTML5VideoViewProxy$VideoPlayer.play(HTML5VideoViewProxy.java:245)
at android.webkit.HTML5VideoViewProxy.handleMessage(HTML5VideoViewProxy.java:447)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5365)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(NativeStart.java)
有什么想法吗?我也有android:hardwareAccelerated =&#34; true&#34;在清单中的应用程序标记中。
P.S。在我的nexus 5和带有棒棒糖版本的motorola设备上正常工作。