通过加载YouTube视频I帧中的Andr​​oid的WebView [英] Loading Youtube video through i-frame in android webview

查看:178
本文介绍了通过加载YouTube视频I帧中的Andr​​oid的WebView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用我的帧来加载YouTube视频到Android的WebView

i want to load youtube video to android webview using i frame

这是我的布局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>

我的code是

My Code is

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", "");

     }
} 

此外,我提供了&LT;使用-权限的Andr​​oid:名称=android.permission.INTERNET对/&GT;

&放大器; 安卓hardwareAccelerated =真正的

当我运行此我没有得到任何结果它只是显示一个黑色的屏幕

when i run this i didn't get any result its just showing a black screen

我尝试<一href="http://stackoverflow.com/questions/11117720/play-video-file-from-youtube-in-android?answertab=active#tab-top">this 。但这为我提供视频名为.3gp质量。但我需要在原有的品质从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 .can anybody help me?

我用尽量code &LT;对象&gt;&LT; /对象&gt; &LT;视频&GT;&LT; /视频&GT; IFRAME >。但它并没有解决我的问题。

I try code using <object></object> and <video></video> instead of iframe. but it didn't solve my issue.

当我在模拟器上运行此code就说明

when i run this code on emulator it shows

pressing播放按钮在

Before Pressing Play Button

在pressing播放视频按钮

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.

我尝试用我的文档框架附加到它正常工作的电话,以及模拟器

i try i frame 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>";

所以,请帮我加载视频到这个帧。你能告诉我在我的code出错

So please help me to load videos to this frame. can you tell me what goes wrong in my code

(我的手机上运行)。可有人告诉我什么问题? 还将对的iframe Android 2.1的工作?

(i run it on phone) .Can anybody tell me whats the problem? also will iframe work on Android 2.1?

没有任何人试图 YouTube API取得

推荐答案

随着 Android的web视图文档中所述

HTML5视频支持

为了支持在应用程序中嵌入HTML5视频,你需要有硬件加速开启设置WebChromeClient

In order to support inline HTML5 video in your application, you need to have hardware acceleration turned on, and set a WebChromeClient.

有关全屏支持,onShowCustomView(查看,WebChromeClient.CustomViewCallback)和onHideCustomView()的实现是必需的,getVideoLoadingProgressView()是可选的。

For full screen support, implementations of onShowCustomView(View, WebChromeClient.CustomViewCallback) and onHideCustomView() are required, getVideoLoadingProgressView() is optional.

这篇关于通过加载YouTube视频I帧中的Andr​​oid的WebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆