Vimeo嵌入显示白屏/缺少进度条

时间:2016-07-11 13:30:46

标签: android webview vimeo

我在我的某个应用中使用了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();
    }

  }

1 个答案:

答案 0 :(得分:1)

我想为您提供一种轻微的替代方法。你的代码中有一个硬编码的html iframe,带有动态代码段。 Vimeo通过他们的网络API为您提供这个html iframe,它包含在每个Video对象中。 ReadMe中包含example有关如何发出视频请求,然后在WebView中播放它的信息。完全披露,我是这个图书馆的作者之一。

相关问题