如何在 Android 上的 WebView 中嵌入 YouTube 剪辑 [英] How to embed a YouTube clip in a WebView on Android

查看:14
本文介绍了如何在 Android 上的 WebView 中嵌入 YouTube 剪辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能解释为什么我无法在 Android 手机上点击和播放 youtube 剪辑放在 webview 中?

Can anyone shed any light on why I'm unable to click and play a youtube clip on an Android handset when placed inside a webview?

我已经将一个非常简单的应用程序放在一起(它正在扩展,但不是马上),它有一个使用 Android SDK 分配的网络视图.

I've put a very simple app together (it's being extended, but no right away) and it has a web view assigned using the Android SDK.

webview 的其余部分按预期工作(文本、图像、css 等),但是,YouTube 剪辑不会显示,它们只会显示为黑色或白色矩形(视频应嵌入的位置).

The rest of the webview works as expected (text, images, css etc), however, the YouTube clips will not show, they just show as black or white rectangles (where the video embed should be).

我们使用相同的视图在等效的 iPhone 应用上显示内容,没有任何问题.

We use the same view to display content on the iPhone app equivalent, without any issues.

这是使用基本的 Flash 嵌入,iPhone 上的 Safari 浏览器将它们转换为 H.264 并在 QuickTime 中很好地播放.

This is using a basic flash embed, the Safari browser on iPhone converts these to H.264 and plays them nicely in QuickTime.

Android 可以做同样的事情吗??

Can Android do the same??

这里以嵌入代码为例....

Here is the embed code, as an example....

<object width="120" height="73">
    <param name="movie" value="http://www.youtube.com/watch?v=ZVYIBIlTIQs&feature=youtube_gdata"></param>
    <param name="allowFullScreen" value="true"></param>
    <param name="allowscriptaccess" value="always"></param>
    <embed src="http://www.youtube.com/watch?v=ZVYIBIlTIQs&feature=youtube_gdata" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="120" height="73"></embed>
</object>

推荐答案

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

I am not sure if this is what you need. Anyway I hope the following be useful. You can use the iframe method that youtube provides to play its videos. If the browser supports html5 will show the video with it, otherwise with flash.

您可以使用以下代码作为示例 <iframe class="youtube-player" type="text/html" width="640" height="385" src="http://www.youtube.com/embed/bIPcobKMB94" frameborder="0">

You can use the following code as an example <iframe class="youtube-player" type="text/html" width="640" height="385" src="http://www.youtube.com/embed/bIPcobKMB94" frameborder="0">

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

in the above example the video id is bIPcobKMB94. You can change this id and show your video.

您可以在此处

有关 youtube iframe 的更多信息

YouTube HTML5 视频播放器

这篇关于如何在 Android 上的 WebView 中嵌入 YouTube 剪辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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