【问题标题】:How to play vemio video on Android app using iframe?如何使用 iframe 在 Android 应用上播放 vimeo 视频?
【发布时间】:2020-04-06 18:17:17
【问题描述】:
我正在使用视频网络库 - https://github.com/vimeo/vimeo-networking-java
但无法在我的 android 应用中播放视频。我不正确地了解 HTML iframe
在官方链接中,它显示-
Video video = ...; // obtain a video in a manner described in the Requests section
String html = video.embed != null ? video.embed.html : null;
if(html != null) {
// html is in the form "<iframe .... ></iframe>"
// display the html however you wish
}
我需要在这里放置什么代码。我无法理解。如果你知道?
【问题讨论】:
标签:
android
vimeo
vimeo-api
vimeo-player
vimeo-android
【解决方案1】:
您不需要任何库即可在 Iframe 中使用 Vimeo 播放器。
这是一个例子:
vimeoPlayer.java 文件:
public class vimeoPlayer extends AppCompatActivity {
private WebView myWebView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_vimeo_player);
myWebView=(WebView)findViewById(R.id.webview);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
myWebView.loadDataWithBaseURL("https://vimeo.com/47412289","<iframe src=\"https://player.vimeo.com/video/47412289\" width=\"100%\" height=\"100%\" frameborder=\"0\"></iframe>","text/html", "utf-8",null);
}
}
activity_vimeo_player.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".vimeoPlayer">
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
AndroidManifest.xml 文件
...
<uses-permission android:name="android.permission.INTERNET" />
...