Android WebView自适应Youtube无法播放 [英] Android WebView Responsive Youtube not playing

查看:216
本文介绍了Android WebView自适应Youtube无法播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常基本的WebActivity,用于提供样式为

I have a very basic WebActivity that serves up a page that has the styling of

CSS

.video-container {
position: relative;
padding-bottom: 56.25%;
padding-top: 30px; height: 0; overflow: hidden;
}

.video-container iframe,
.video-container object,
.video-container embed {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}

Next, edit add some HTML around your embed code.
HTML

<div class="video-container"><iframe width="853" height="480" src="https://www.youtube.com/embed/xxxxxx" frameborder="0" allowfullscreen</iframe</div>

如果我使用设备上的浏览器查看此页面,则该页面会加载,并且视频可以正常播放.

If I view this page with the browser on the device, the page loads and the video plays just fine.

但是,如果我使用编程到我的应用程序中的webview并加载页面,单击类似的按钮,则会在youtube视频窗口(加载微调器之后)收到一条消息:发生了错误.请稍后重试(播放ID:xxxxxx)了解详情"

However if I use a webview programmed into my app, and load the page,clicking on the like, I get a message on the youtube video window (after the loading spinner) of "An error occurred. Please try again later (Playback ID: xxxxxx) Learn More"

其中的更多内容不会显示任何有用的信息.关于如何去了解正在发生的事情的想法? Android Studio logcat没有显示任何问题?

of which learn more does not display anything useful. Idea's on how to go about seeing what is going on? The Android Studio logcat is not displaying any issues?

推荐答案

因此,要播放来自YouTube的嵌入式iframe视频,还需要更多参数.

so it turns out that there are a few more params needed to play embeded iframe videos from YouTube.

必须将以下内容添加到url字符串的末尾

Had to add the following to the end of the url string

src ="https://www.youtube.com/embed/xxxxxxxxx?version=3&enablejsapi=1"

src="https://www.youtube.com/embed/xxxxxxxxx?version=3&enablejsapi=1"

这篇关于Android WebView自适应Youtube无法播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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