【发布时间】:2012-12-18 20:21:44
【问题描述】:
我想使用 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>
我的代码是:
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", "");
}
}
另外我提供<uses-permission android:name="android.permission.INTERNET"/>
&android:hardwareAccelerated="true"
当我运行它时,我没有得到任何结果,它只是显示黑屏
我试过this 。但这为我提供了.3gp Quality 上的视频。但我需要来自 youtube 的原始质量视频。这就是我使用iframe 的原因。
我尝试使用<object></object> 和<video></video> 而不是iframe 编写代码。但它并没有解决我的问题。
当我在模拟器上运行这段代码时,它会显示
按下播放按钮之前
按下视频播放按钮后
我认为我们不能在模拟器上播放视频,因为它是一个虚拟设备
但是当我在手机上运行它时,它甚至没有显示这个结果。
我尝试 iframe 并附加一个文档,它在手机和模拟器上都可以正常工作
String customHtml = "<iframe src='http://docs.google.com/viewer?url=http://www.iasted.org/conferences/formatting/presentations-tips.ppt&embedded=true' width='100%' height='100%' style='border: none;'></iframe>";
所以请帮我把视频加载到这个框架中。
(我在手机上运行)。有什么问题? iframe 也可以在 Android 2.1 上运行吗?
有人试过Youtube Api 吗?
【问题讨论】:
标签: android iframe youtube android-webview