在Android WebView中通过iframe加载Youtube视频 [英] Loading Youtube video through iframe in Android webview
问题描述
我想使用iframe将youtube视频加载到Android Webview
I want to load youtube video to Android webview using iframe
这是我的布局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"
运行此程序时,我没有得到任何结果,只是显示黑屏
when I run this I didn't get any result its just showing a black screen
我尝试了此 .但这为我提供了.3gp Quality
上的视频.但我需要来自YouTube的原始质量的视频.这就是为什么我使用iframe
.
I tried this .but this provide me video on .3gp Quality
. but I need the videos from youtube on original quality. That's why I am using iframe
.
我尝试使用<object></object>
和<video></video>
而不是iframe
的代码.但这并不能解决我的问题.
I try code using <object></object>
and <video></video>
instead of iframe
. but it didn't solve my issue.
当我在模拟器上运行此代码时,它会显示
when I run this code on emulator it shows
按下播放按钮之前
在视频上按播放"按钮后
After Pressing Play button on video
我认为我们无法在模拟器上流式传输视频,因为它是虚拟设备
I think we cannot stream videos on emulator since it is a virtual device
但是当我在手机上运行它时,它甚至都没有显示出结果.
But when I run this on phone it's not even showing this result.
我尝试将带有文档的iframe附加到手机以及仿真器上
I try iframe with a document attach to it works fine on phone as well as emulator
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>";
所以请帮助我将视频加载到此框架.
So please help me to load videos to this frame.
(我在手机上运行).有什么问题? iframe也可以在Android 2.1上运行吗?
(I run it on phone). What's the problem? also will iframe work on Android 2.1?
有人尝试过 Youtube Api 吗?