UIWebview 内的 Youtube 视频自动播放

2023-10-22移动开发问题
3

本文介绍了UIWebview 内的 Youtube 视频自动播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我在这个论坛中发现了很多关于嵌入 youtube 视频和自动播放的问题,但没有一个能解决我所有的疑问.

I found many questions in this forum regarding embedding youtube video and autoplay, but none of them cleared all my doubts.

我找到了两种在 UIWebView 中嵌入 youtube 视频的方法

I found two methods to embed youtube video in UIWebView

1)

NSString *youTubeHTMLTemplate = @"<html><head><style type="text/css">body { background-color: transparent;color: white;}</style></head><body style="margin:0"><embed id="yt" src="%@" type="application/x-shockwave-flash" width="%0.0f" height="%0.0f"></embed></body></html>"; 
finalHtml = [NSString stringWithFormat:youTubeHTMLTemplate, fullYopuTubeUrl, htmlFrameWidth, htmlFrameHeight];

2)

NSString *youTubeHTMLTemplate = @"<html><body style="margin:0;padding:0;"><iframe class="youtube-player" type="text/html" width="%f" height="%f" src="http://www.youtube.com/embed/%@" frameborder="0" allowfullscreen></iframe></body></html>";
finalHtml = [NSString stringWithFormat:youTubeHTMLTemplate, htmlFrameWidth, htmlFrameHeight, videoID];

如果我使用 (1) 方法并遵循 这里给出的方法 我的视频会自动播放.想法是在 UIWebView 中找到按钮并向其发送修饰事件.

If I use (1) method and follow the approach given here my video autoplays. Idea is to find button in UIWebView and send touch up event to it.

如果我使用 (2) 并遵循相同的方法,视频不会自动播放.

If I use (2) and follow the same approach video does not autoplay.

我认为建议使用 (2) 方法,因为 (1) 仅适用于 Flash 视频(对吗?).

I think that the (2) approach is recommended as the (1) is for Flash Videos only (Right?).

以任何方式(2)是可能的吗?这个链接说不.

Is by any means (2) is possible ? This link says NO.

谁能确认一下

  • 如果我是正确的,建议使用 (2)
  • 无法使用 (2) 自动播放.

推荐答案

Q.如果我是正确的,推荐(2)

Q. If I am correct that (2) is recommended

A.是 (2) 方法适用于不支持闪存的 i 设备.

A. Yes (2) method is for i-devices where no flash support.

问.无法使用 (2) 进行自动播放.

Q. Autoplay with (2) is not possible.

A.目前无法自动播放.

A. No autoplay is not possible as of now.

更新:我可以使用 Youtube JS API 自动播放 youtube 视频,请参阅 https://developers.google.com/youtube/js_api_reference

Update: I am able to autoplay youtube video by using Youtube JS APIs see https://developers.google.com/youtube/js_api_reference

只需从 onPlayerReady 调用 playVideo

Just call playVideo from onPlayerReady

function onPlayerReady(event) {
                event.target.playVideo();                    
            }

这篇关于UIWebview 内的 Youtube 视频自动播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

硬件音量按钮更改应用程序音量
Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)...
2024-08-12 移动开发问题
10

恢复游戏 cocos2d
Resume game cocos2d(恢复游戏 cocos2d)...
2024-08-12 移动开发问题
6

Cocos2D + 仅禁用 Retina iPad 图形
Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)...
2024-08-12 移动开发问题
10

[ios.cocos2d+box2d]如何禁用自动旋转?
[ios.cocos2d+box2d]how to disable auto-rotation?([ios.cocos2d+box2d]如何禁用自动旋转?)...
2024-08-12 移动开发问题
7

从 Documents 目录存储和读取文件 iOS 5
Storing and reading files from Documents directory iOS 5(从 Documents 目录存储和读取文件 iOS 5)...
2024-08-12 移动开发问题
9

如何在 cocos2d 环境之外实现 cocos2d 游戏的虚拟摇杆?
How can I implement a virtual joystick for a cocos2d game outside the cocos2d environment?(如何在 cocos2d 环境之外实现 cocos2d 游戏的虚拟摇杆?)...
2024-08-12 移动开发问题
13