android - 如何在android中播放vimeo视频。我尝试过使用 webview。有没有其他方法可以播放 vimeo 视频?
问题描述
我曾尝试使用 webview 播放 vimeo 视频。但它看起来并不好,它使屏幕可滚动。Vimeo 提出了另一种使用本机播放的播放方式,但它有特定的使用要求
原生播放的基本要求是:
- 用户必须登录。
- 用户必须是视频的所有者。
- 用户必须是 PRO 或更高版本(或应用程序必须具有“可以访问所有者的视频文件”功能)。
- 令牌必须具有 video_files 范围。用户必须是发出请求的 API 应用的所有者
我没有专业帐户。我如何使用本机播放来测试,如果一切顺利,我会去 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: ");
}
});
}
有没有其他方法可以播放视频?
解决方案
就我而言,我使用了 Exoplayer。Exoplayer 更具可定制性。您只需要从配置链接中提取 url 链接。您可以使用改造来提取视频网址。
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。
推荐阅读
- java - 无法运行创建的 -jar 文件
- java - 是否可以在 Fitnesse 服务器 VM 中运行 Slim 客户端
- python - PIP 安装 pysftp:连接超时
- r - 如果单击 visNetwork 提示中的取消,操作选项会消失
- python - 将布局定位到主布局python Autodesk Maya的底部
- powershell - 在第二个`/`之后存储所有内容
- ios - 如何使用已安装的 SSL 证书来保护 iOS 应用程序?
- java - Java Draw 不动的蛇
- reactjs - 如何等待调度动作完成?
- reactjs - 为什么 useContext 在我的函数中不起作用?