我想使用iframe将youtube视频加载到Android webview
这是我的布局Xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/white"
android:id="@+id/mainLayout">
<WebView
android:background="@android:color/white"
android:id="@+id/webView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
我的代码是:
public class WebTube extends Activity {
private WebView wv;
String html = "<iframe class=\"youtube-player\" style=\"border: 0; width: 100%; height: 95%; padding:0px; margin:0px\" id=\"ytplayer\" type=\"text/html\" src=\"http://www.youtube.com/embed/WBYnk3zR0os"
+ "?fs=0\" frameborder=\"0\">\n"
+ "</iframe>";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
wv = (WebView)findViewById(R.id.webView);
wv.getSettings().setJavaScriptEnabled(true);
wv.loadDataWithBaseURL("", html , "text/html", "UTF-8", "");
}
}
Run Code Online (Sandbox Code Playgroud)
我也提供 <uses-permission android:name="android.permission.INTERNET"/>
& android:hardwareAccelerated="true"
当我运行这个时,我没有得到任何结果它只是显示黑屏
我试过这个.但是这给我提供了视频.3gp Quality.但是我需要来自youtube的原始质量的视频.这就是我使用的原因 …