【问题标题】:How to play vimeo video in android. I have tried using webview. Is there any other way to play vimeo video?如何在android中播放vimeo视频。我尝试过使用 webview。有没有其他方法可以播放 vimeo 视频?
【发布时间】:2021-01-16 10:39:35
【问题描述】:

我尝试过使用 webview 播放 vimeo 视频。但它看起来并不好,它使屏幕可滚动。 Vimeo 建议了另一种使用本机播放的播放方式,但它有特定的使用要求

原生播放的基本要求是:

  1. 用户必须登录。
  2. 用户必须是视频的所有者。
  3. 用户必须是 PRO 或更高版本(或应用必须具有“可以访问所有者的视频文件”功能)。
  4. 令牌必须具有 video_files 范围。 用户必须是发出请求的 API 应用的所有者

我没有 PRO 帐户。我如何使用本机播放来测试,如果一切顺利,我会去 vimeo PRO

这是我使用 WEBVIEW 玩的代码

 VimeoClient.getInstance().fetchNetworkContent(uri, new ModelCallback<Video>(Video.class) {
            @Override
            public void success(Video video) {
                String html = video.embed != null ? video.embed.html : null;
                if(html != null) {
                    WebView webView = (WebView) findViewById(R.id.webView);
                    WebSettings webSettings = webView.getSettings();
                    webSettings.setJavaScriptEnabled(true);
                    webView.loadData(html, "text/html", "utf-8");
                }
            }

            @Override
            public void failure(VimeoError error) {

                Log.d(TAG, "failure: ");
            }
        });
    }

还有其他播放视频的方法吗?

【问题讨论】:

    标签: android vimeo vimeo-api vimeo-android


    【解决方案1】:

    在我的例子中,我使用了 Exoplayer。 Exoplayer 更具可定制性。您只需要从配置链接中提取 url 链接。您可以使用 retrofit 来提取视频网址。

    BASE_URL = "https://player.vimeo.com/video/"

    您将需要使用如下的 get 方法:

    @GET("{id}/{config}")
    Call<JsonObject>getVideoLink(@Path("id") String id, @Path("config") String config);
    

    您将从视频链接中获取 id。示例:“https://vimeo.com/123456789/”这里的id是:123456789。

     JsonObject jsonObject = response.body();
                JsonObject req = jsonObject.getAsJsonObject("request");
                JsonObject file = req.getAsJsonObject("files");
                JsonArray arr = file.getAsJsonArray("progressive");
                String url = arr.get(0).getAsJsonObject().get("url").getAsString();
               
    

    现在你可以使用这个 url 来玩了。不要忘记先启动 Exoplayer。

    【讨论】:

    • 感谢回复,我需要在“config”中提供什么?
    • 要获取视频 JSON,您需要点击链接。示例 "player.vimeo.com/video/video_id/config" 。您只需要传递 video_id 即可。您的视频 ID 可能是 123455678..etc
    • 这里,我们需要 id 和 config。 @GET("{id}/{config}") CallgetVideoLink(@Path("id") String id, @Path("config") String config); 假设视频链接是vimeo.com/1234567 我知道 id = 1234567 但 config = ?我从哪里得到配置?
    • config =config 如果您的链接是 vimeo.com/1234567,那么您将使用此链接:player.vimeo.com/video/1234567/config 进行改造。
    • 谢谢,它有效。但我想知道什么时候需要使用 vimeo 文档中提到的范围来访问我的私人空间
    猜你喜欢
    • 1970-01-01
    • 2016-12-28
    • 2012-02-20
    • 2013-03-31
    • 1970-01-01
    • 2018-12-09
    • 2013-05-18
    • 2012-11-02
    • 1970-01-01
    相关资源
    最近更新 更多