我在我的某个应用中使用了Vimeo和webview,但在某些设备中,它并没有很好地运行。在我的xaiomi(API-19)上它没有显示视频进度条和我的S4(API-21)第一次看到它正确显示的视频,但是第二次它显示白屏,而不是只在我刚看的视频上,但在其他所有Vimeos视频中,我尝试播放。有人知道我做错了什么吗?或另一种有效的方式?这是我的VimeoPlayer活动。
public class VimeoPlayer extends Activity {
private HTML5WebView mWebView;
private ModelVideo video;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mWebView = new HTML5WebView(this);
video = getIntent().getParcelableExtra("video");
//Auto playing vimeo videos in Android webview
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setAllowFileAccess(true);
mWebView.getSettings().setAppCacheEnabled(true);
mWebView.getSettings().setDomStorageEnabled(true);
mWebView.getSettings().setPluginState(PluginState.OFF);
mWebView.getSettings().setAllowFileAccess(true);
String html = "<iframe src=\"https://player.vimeo.com/video/" + video.getVideoUrl() +
"?title=0&byline=0&portrait=0&color=000000\" width=\"" + mWebView.getWidth() + "\" height=\"" +
mWebView.getHeight() + "\" frameborder=\"0\" webkitallowfullscreen=\"\" mozallowfullscreen=\"\" allowfullscreen=\"\"" +
"style=\"margin-top:-8px;margin-bottom:-8px;margin-left:-8px;margin-right:-8px;padding:0;width:105%;height:100%;background-color:#000000;\"></iframe>";
String mime = "text/html";
String encoding = "utf-8";
mWebView.loadDataWithBaseURL(null, html, mime, encoding, null);
setContentView(mWebView.getLayout());
//Esconder a Status Bar
View decorView = getWindow().getDecorView();
// Hide the status bar.
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
// Remember that you should never show the action bar if the
// status bar is hidden, so hide that too if necessary.
ActionBar actionBar = getActionBar();
if(actionBar!=null) {
actionBar.hide();
}
}
@Override
public void onPause() {
super.onPause();
}
@Override
protected void onDestroy() {
super.onDestroy();
mWebView.destroy();
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
mWebView.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
@Override
public void onBackPressed() {
super.onBackPressed();
mWebView.destroy();
finish();
}
}