2013-02-15 65 views
0

嗨,我想在android中嵌入youtube视频。 这就是在屏幕上显示出来 - http://imgur.com/5YEVq24android webview -youtube嵌入不工作

这是我的WebView代码

<img src="illustration.jpg" /> 
<video src="http://www.youtube.com/watch?v=dvWy9NXiZZI" width="320" height="240" autobuffer controls onclick="this.play();"/> 

图显示了罚款,但图像下面的视频显示不出来,它也不当我玩点击它。

任何机构可以帮助我吗?

回答

0

您是否在您的webview中启用了JavaScript? 如果没有 试试这个,我在这里启用JavaScript

WebView web=(WebView) findViewById(R.id.webView1); 
web.getSettings().setJavaScriptEnabled(true); 
web.loadUrl("http://www.youtube.com/watch?v=dvWy9NXiZZI"); 

这是XML

main.xml中

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" > 

<android.webkit.WebView 
    android:id="@+id/webView1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 
</android.webkit.WebView> 

另外还有一个问题是,视频可以不由于硬件资源有限,在某些设备上播放。

0
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.example.house" 
android:versionCode="1" 
android:versionName="1.0" xmlns:tools="http://schemas.android.com/tools"> 

试图把 “的xmlns:工具=” http://schemas.android.com/tools”

和android:硬件加速= “你的清单

<activity android:name="Main_Webview" android:hardwareAccelerated="true" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:configChanges="orientation|keyboardHidden"></activity>  
+0

http://imgur.com/vc1CClG。仍然不适合我。正如你所说,我改变了舱单。 – 2013-02-15 10:00:07

+0

尝试检入您的项目属性> Android,如果您的构建目标高于3.0或蜂窝 – Cjames 2013-02-16 04:55:32

2

真”这个小除了在清单中的应用程序级别的伎俩:

android:hardwareAccelerated="true" 
1

简单的解决方案

只需使用Iframe。

<iframe width="350" height="240" src="https://www.youtube.com/embed/VIDEO_ID" frameborder="0" allowfullscreen></iframe>