IOS Webview 中的 Youtube iFrame 播放器加载非常缓慢 [英] Youtube iFrame player in IOS Webview loads very slowly

查看:61
本文介绍了IOS Webview 中的 Youtube iFrame 播放器加载非常缓慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 IOS 的 Web 视图中使用此处定义的标准 YouTube iFrame 播放器.一切正常,除了视频在宽带网络上加载持续时间超过 6 秒.当我使用 Safari 在 Youtbue.com 上、在同一网络上、使用同一台 iPad 加载完全相同的视频时,视频始终在 3 秒内加载.

I'm using the standard YouTube iFrame player as defined here within a Webview on IOS. Everything works as it should, except the videos consistently take over 6 seconds to load on a broadband network. When I use Safari to load the exact same video on the Youtbue.com, on the same network, using the same iPad, the video consistently loads in under 3 seconds.

有谁知道为什么 IOS Webview 视频的加载时间是原来的两倍?

Does anyone know why the IOS Webview videos are taking twice as long to load ?

还是 YouTube(由 Google 拥有)故意在其网站上加载视频比使用播放器 API 的应用程序更快?

Or is YouTube (owned by Google) deliberately loading videos on their website faster than apps using their player apis ?

关于我的方法的一些其他数据点:1) 我只测量视频在我的应用程序中加载的时间,而不是 webview 的加载,甚至是包含 Youtube iframe 的 webview 中的 html 页面的加载.我在 webview 加载 Youtube iFrame 后开始测量.2) Youtube 应用程序与使用 Safari 的 YouTube 网站类似.我假设 Youtube App 使用 Webview.3)结果似乎在不同的日子有所不同.YouTube 网站和应用视频的平均速度总是更快,但速度因天数而异.

A couple other data points as to my methodology: 1) I'm only measuring the time for a video to load in my app, not the loading of the webview or even the html page within the webview that contains the Youtube iframe. I start measuring after the webview has loaded the Youtube iFrame. 2) The Youtube App performs similarly to the YouTube website using Safari. I assume Youtube App uses a Webview. 3) The results seem to vary on different days. YouTube Website and App videos are always faster on average, but the amount varies by days.

推荐答案

我觉得(由 Google 拥有)"评论暗示了一些我认为不存在的改变动机..

I feel the "(owned by Google)" comment suggests some alterer motive which I don't believe exists..

这里可能有几个不同的问题:

There are several different issues which may be at work here:

1) 您似乎在使用 Mobile Safari 测试 Youtube.com,并使用 webview 测试嵌入式播放器:

这不是一个公平的比较,因为 webview 已被证明比 safari 慢得多.(例如 http://www.guypo.com/mobile/ios-browsers-速度烘焙/ )

This is not a fair comparison, as the webview has been shown to be very significantly slower than safari. (e.g. http://www.guypo.com/mobile/ios-browsers-speed-bakeoff/ )

2) 您没有明确说明您正在测量的加载时间

这次是不是在创建webview,设置浏览器环境?

Are you creating the webview in this time and setting up the browser environment?

您是否正在加载包含嵌入播放器代码的脚本标记的文档?

Are you loading the document which includes the script tag for the embedded player code in this time?

在您加载视频时,Safari 是否有 youtube.com 的热缓存?

Did Safari have a hot cache for youtube.com at the time you loaded the video?

许多浏览器在您输入时开始在后台加载请求,然后再点击加载页面 - 这些性能调整可以显着减少加载网站的明显时间,但会使比较变得困难.

Many browsers start loading requests in the background as you type, before you tap to load a page - these kind of performance tweaks can significantly reduce apparent time to load a site, but make comparisons difficult.

3) 他们优化的常见用户故事不同

在几乎所有将 YouTube 播放器 API 插入页面或网站的情况下,视频不会自动开始播放.

In almost all situations where the YouTube player API is inserted into a page or a website, the video does not automatically start playing.

相比之下,几乎每个YouTube 观看页面加载都会自动开始播放视频.

By comparison, almost every YouTube watch page load begins playing the video automatically.

YouTube 之前在演示文稿中讨论过的优化之一是将视频流的第一部分内嵌到页面中甚至在视频播放器加载之前.

One of the optimisations which YouTube have discussed in presentations before is in-lining the first part of the video stream into the page even before the video player loads.

这是为了更快的视频播放而对额外用户带宽的权衡,当您知道用户肯定会播放视频时,这是有道理的:但是,如果他们要为嵌入式视频执行此操作,则会显着减慢速度播放视频的玩家的加载时间并不总是开始播放 - 这在世界上所有网站中占相当大的比例!

This is a trade-off of extra user bandwidth for faster video playback which makes sense when you know the user is going to definitely play the video: however if they were to do this for embedded videos then it would significantly slow down the loading time for players with videos which did not always start playing - which is a fairly significant percentage of all of the websites in the world!

4) YouTube 在这两种情况下的介入点不同,只能在稍后开始优化嵌入式播放器的体验.

YouTube 能够在 youtube.com 上进行优化,而它在使用 html5 播放器 API 的第三方网站/应用上无法做到这一点.

YouTube is able to do optimisations on youtube.com which it is unable to do on third party sites/apps using their html5 player API.

在 youtube.com 上观看视频的情况下:YouTube 从第一个 http 请求开始就参与其中 - 他们知道您正在播放哪个视频,并且知道您说您在使用哪个浏览器(因此可以优化体验尽可能预加载正确的视频和/或视频播放器).

In the case of watching a video on youtube.com: YouTube are involved right from the first http request - they know which video you are playing, and they know which browser you say you are on (so can optimise the experience as much as possible to pre-load the correct video and/or video player).

在嵌入 iframe 的情况下:

In the case of embedding an iframe:

  • 浏览器首先加载您的页面,然后它必须解析并从中提取网址.
  • 然后它向 YouTube 请求 javascript(请注意,如果您使用的是 javascript 播放器 API 而不是直接嵌入的 iframe,则需要将其缓存在浏览器上,因此 YouTube 仍然无法优化此视频的性能此时)
  • 整个页面加载完毕后,它可以创建一个指向 YouTube 的 iframe(所有这些都需要 CPU 和内存管理时间)
  • 这个点上,YouTube 可以开始优化一些东西,以尝试让体验更快.
  • The browser first loads your page, which it then has to parse and extract urls from.
  • Then it makes a request for javascript from YouTube (note that if you are using the javascript player API rather than the embedded iframe direct then that needs to be cached on the browser, so YouTube still can't optimise performance of this video at this point)
  • Once your entire page has finished loading, it can create an iframe pointing to YouTube (all of this takes time on the CPU and memory management time)
  • At this point, YouTube can start optimising things to try to make the experience faster.

这篇关于IOS Webview 中的 Youtube iFrame 播放器加载非常缓慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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