Vimeo 嵌入显示白色 screen/missing 进度条
Vimeo embed showing white screen/missing progressbar
我在我的一个应用程序中将 Vimeo 与 webview 结合使用,但在某些设备上效果不佳。在我的 xaiomi(API-19) 上它没有显示视频进度条,在我的 S4(API-21) 上我第一次看视频时它显示正确,但在第二次它显示白屏,不仅在我刚刚观看的视频中,而且在我尝试播放的所有其他 Vimeos 视频中。有人知道我做错了什么吗?或另一种有效的方式?这是我的 VimeoPlayer activity.
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();
}
}
我在我的一个应用程序中将 Vimeo 与 webview 结合使用,但在某些设备上效果不佳。在我的 xaiomi(API-19) 上它没有显示视频进度条,在我的 S4(API-21) 上我第一次看视频时它显示正确,但在第二次它显示白屏,不仅在我刚刚观看的视频中,而且在我尝试播放的所有其他 Vimeos 视频中。有人知道我做错了什么吗?或另一种有效的方式?这是我的 VimeoPlayer activity.
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();
}
}