想要将嵌入代码的YouTube视频播放到webview中,并在同一webview中显示html内容

时间:2015-01-13 10:50:28

标签: android webview youtube

我在使用嵌入代码显示youtube视频到webview时遇到问题。我通过imagess和一些文本内容从webservice获取html内容。还有youtube嵌入视频代码。我已经成功显示了图片和文字,但是当youtube嵌入代码时,它会显示错误,例如“网页不可用”。

所以任何人都解决了这个问题,然后在这里回复。

WebView wvDesc = (WebView) findViewById(R.id.wvDesc);
wvDesc.getSettings().setJavaScriptEnabled(true);
wvDesc.getSettings().setPluginState(WebSettings.PluginState.ON);

final String mimeType = "text/html";
final String encoding = "UTF-8";
wvDesc.loadDataWithBaseURL(null, strContent, mimeType, encoding, null);
// where strContent is string which is html content need to display the text and youtube video

1 个答案:

答案 0 :(得分:0)

我不确定这是否是您所需要的。无论如何,我希望以下内容有用。您可以使用youtube提供的iframe方法播放其视频。如果浏览器支持html5将使用它显示视频,否则使用flash。

您可以使用以下代码作为示例

在上面的例子中,视频ID是bIPcobKMB94。您可以更改此ID并显示您的视频。

您可以在此处访问其实时示例

youtube iframe的更多信息

YouTube HTML5视频播放器