Youtube嵌入了在webview中无效的视频.这段代码出了什么问题?

The*_*der 8 embed youtube video android android-webview

我是android的新手.我现在面临两个问题 1.我解析了xml文件并在webview中显示它,其中包含视频和文本.当我点击视频时,它将无法播放.在xml视频中有youtube嵌入.

为什么会这样?

1.第一个问题:代码和图像

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);
}
Run Code Online (Sandbox Code Playgroud)

当我浏览视频时,它开始浏览并只显示黑屏,然后什么都不会发生.

![] [1]

2. 我有你管的嵌入式视频网址,我用html标签给出并尝试加载它.它们也不适合我.我检查了一些问题和博客,也没有设置,然后也无法显示视频.将不胜感激.谢谢.

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");
Run Code Online (Sandbox Code Playgroud)

在这种情况下,我将youtube embeded视频加载到webview,但它们也无法正常工作.

![] [2]

我正在使用android 2.3.3version.我也想要澄清,有任何要求在模拟器上安装adobe flash player,但我认为不,因为视频在浏览器中工作.任何人都可以告诉我是对还是错?请尽量给我解决方案因为我很久以前就遇到了这个问题..

我也尝试使用object标签如下:

        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>";
Run Code Online (Sandbox Code Playgroud)

aya*_*aya 8

你需要

查看http://developer.android.com/reference/android/webkit/WebView.html并阅读HTML5视频支持部分.

这对我有用......


slh*_*ddn 2

我猜你在 html 代码中使用了 iframe 标签。使用对象标签更改它。我的意思是,你必须使用 object 而不是 iframe。这里有一个例子:

<object width="480" height="330"><param name="movie" 
value="http://www.youtube.com/v/"here is your video id"?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/v/"here is your video id"?version=3&amp;hl=pt_BR&amp;rel=0" 
type="application/x-shockwave-flash" width="480" height="330" allowscriptaccess="always" allowfullscreen="true" /></object>
Run Code Online (Sandbox Code Playgroud)

使用下面的代码:

webview.getSettings().setPluginsEnabled(true);
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setAllowFileAccess(true);
webview.loadUrl(url);
Run Code Online (Sandbox Code Playgroud)

如果您的问题得到解决,请尝试此操作并将其加厚为可接受的值:)