嵌入的YouTube视频不工作在web视图。有什么不对的code? [英] Youtube embed videos not working in webview. What's wrong with this code?

查看:122
本文介绍了嵌入的YouTube视频不工作在web视图。有什么不对的code?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的机器人。我面临两个问题,现在的 1 。我解析XML文件,并显示出它的WebView包含视频和文字。当我点击视频就不会播放。在XML视频是YouTube的嵌入。

为什么会这样呢?

1。首先的问题:code和图像

 保护无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.web_view);
    意向意图= getIntent();
    字符串urlsting = intent.getStringExtra(STR);
    mWebView =(web视图)findViewById(R.id.webview);
    mWebView.getSettings()setJavaScriptEnabled(真)。
    。mWebView.getSettings()setPluginState(PluginState.ON);
    mWebView.getSettings()setPluginsEnabled(真)。
    mWebView.setInitialScale(100);
    。mWebView.getSettings()setBuiltInZoomControls(真正的);
    mWebView.loadDataWithBaseURL(NULL,urlsting,text / html的,UTF-8,NULL);
}
 

当我clcik视频启动浏览,并只显示黑屏,那么什么都不会发生。

2 我有我的HTML标记给出,并尝试加载它。他们也都没有工作对我来说,你管嵌入视频网址。我检查的问题和博客数量,也取得了不设置那么也无法显示视频。帮助将AP $ P $提前pciated .Thanks。

 字符串视频=&LT;表BGCOLOR = \#666666 \&GT;&LT; TR&GT;&LT; TD&GT;&LT; IFRAME宽度= \300 \高度= \ 260 \FRAMEBORDER = \0 \ID = \播放器\ type=\"text/html\"src=\"http://www.youtube.com/embed/iiLepwjBhZE?enablejsapi=1&origin=example.com\"></iframe></td></tr><tr><td><iframe宽度= \300 \高度= \260 \FRAMEBORDER = \0 \ID = \播放器\ type=\"text/html\"src=\"http://www.youtube.com/embed/lBMMTeuJ_UQ?enablejsapi=1&origin=example.com\"></iframe></td></tr><tr><td><iframe宽度= \300 \高度= \260 \FRAMEBORDER = \0 \ID = \播放器\ type=\"text/html\"src=\"http://www.youtube.com/embed/BZMkY3y7nM0?enablejsapi=1&origin=example.com\"></iframe></td></tr><tr><td></table>";

    mWebView =(web视图)findViewById(R.id.webview);
    mWebView.getSettings()setJavaScriptEnabled(真)。
    。mWebView.getSettings()setPluginState(PluginState.ON);
    mWebView.getSettings()setPluginsEnabled(真)。
    //mWebView.loadDataWithBaseURL(null,load,"text/html","UTF-8",null);
    mWebView.loadData(视频,text / html的,UTF-8);
 

在这种情况下,我加载内嵌的YouTube视频到的WebView但他们也没有工作。

我使用的Andr​​oid 2.3.3version.I也想澄清有关于模拟器安装Adobe Flash Player中的任何要求,但我认为没有,因为影片都工作在浏览器中。谁能告诉我是对还是错?请尽量给我的解决方案,因为我早就坚持这个问题..

我也尝试过使用对象标记如下:

 字符串的obj =&LT;对象的宽度= \300 \高度= \260 \&GT;&LT; PARAM NAME = \电影\ value=\"http://www.youtube.com/embed/iiLepwjBhZE?enablejsapi=1&origin=example.com\"?version=3&amp;hl=pt_BR&amp;rel=0\"></param><param名字= \的allowFullScreen \价值= \真正的\&GT;&LT; /参数&GT;&LT; PARAM NAME = \allowScriptAccess的\值= \永远\&GT;&LT; /参数&GT;&LT;嵌入SRC = \?HTTP://www.youtube.com/embed/iiLepwjBhZE enablejsapi = 1&安培;起源= example.com \版本= 3&放大器;放大器; HL = PT_BR和放大器;放大器;相对= 0 \型= \应用程序/ X-冲击波闪光\WIDTH = \480 \高度= \330 \的allowScriptAccess = \永远\的allowFullScreen = \真正的\/&GT;&LT; /对象&gt;;
 

解决方案

您需要

  • 设置WebChromeClient您的WebView

      web.setWebChromeClient(新WebChromeClient());
     

  • 和打开hardwareAccelerated值

     &lt;应用
    机器人:hardwareAccelerated =真?
     

检查出<一href="http://developer.android.com/reference/android/webkit/WebView.html">http://developer.android.com/reference/android/webkit/WebView.html和阅读HTML5视频支持的部分。

这对我的作品......

I am new to android. I am facing two problems right now 1. I parsed xml file and showed it in webview which contains videos and text . When i click on videos it will not play . In xml videos are youtube embed.

Why is it so?

1.First problem :code and image

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.web_view);
    Intent intent=getIntent();
    String urlsting=intent.getStringExtra("str"); 
    mWebView = (WebView) findViewById(R.id.webview);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setPluginState(PluginState.ON);
    mWebView.getSettings().setPluginsEnabled(true);
    mWebView.setInitialScale(100);
    mWebView.getSettings().setBuiltInZoomControls(true);
    mWebView.loadDataWithBaseURL(null, urlsting,"text/html", "utf-8", null);
}

When i clcik on video it starts browsing and shows only black screen,then nothing will happen.

2. I have you-tube embedded videos url which I given in html tag and try to load it .They are also not working for me. I checked number of questions and blogs and also made no of settings then also unable to show video . Help will be appreciated .Thanks in advance.

String video= "<table bgcolor=\"#666666\"><tr><td><iframe width=\"300\" height=\"260\"     frameborder=\"0\" id=\"player\" type=\"text/html\"src=\"http://www.youtube.com/embed/iiLepwjBhZE?enablejsapi=1&origin=example.com\"></iframe></td></tr><tr><td><iframe width=\"300\" height=\"260\" frameborder=\"0\" id=\"player\" type=\"text/html\"src=\"http://www.youtube.com/embed/lBMMTeuJ_UQ?enablejsapi=1&origin=example.com\"></iframe></td></tr><tr><td><iframe width=\"300\" height=\"260\" frameborder=\"0\" id=\"player\" type=\"text/html\"src=\"http://www.youtube.com/embed/BZMkY3y7nM0?enablejsapi=1&origin=example.com\"></iframe></td></tr><tr><td></table>"; 

    mWebView = (WebView) findViewById(R.id.webview);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setPluginState(PluginState.ON);
    mWebView.getSettings().setPluginsEnabled(true);
    //mWebView.loadDataWithBaseURL(null,load,"text/html","UTF-8",null);
    mWebView.loadData(video,"text/html","UTF-8");

In this case I load the youtube embeded videos to webview but they are also not working.

I am using android 2.3.3version.I also want clarification that is there any requirement of install adobe flash player on emulator, but i think no because videos are working in browser. can anybody tell i am right or wrong?? please try to give me solution because i stuck with this problem long ago..

I also tried using object tag as follows:

        String obj="<object width=\"300\" height=\"260\"><param name=\"movie\" value=\"http://www.youtube.com/embed/iiLepwjBhZE?enablejsapi=1&origin=example.com\"?version=3&amp;hl=pt_BR&amp;rel=0\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\"http://www.youtube.com/embed/iiLepwjBhZE?enablejsapi=1&origin=example.com\" ?version=3&amp;hl=pt_BR&amp;rel=0\" type=\"application/x-shockwave-flash\" width=\"480\" height=\"330\" allowscriptaccess=\"always\" allowfullscreen=\"true\" /></object>";

解决方案

You need to

  • set a WebChromeClient to your WebView

        web.setWebChromeClient(new WebChromeClient());
    

  • and turn on hardwareAccelerated value

    <application
    android:hardwareAccelerated="true"...
    

check out http://developer.android.com/reference/android/webkit/WebView.html and read HTML5 Video support part.

This works for me...

这篇关于嵌入的YouTube视频不工作在web视图。有什么不对的code?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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