javascript - Chrome会自动识别Flash的重要性,然后决定是否自动播放?
阿神
阿神 2017-04-10 16:53:32
[JavaScript讨论组]

lz在HTML页面中播放Flash视频的时候,遇到了一个小问题,那就是如果Flash播放器的宽和高不合适,那么Chrome就会拦截播放器的自动播放,见下图:

然后必须要点击一下播放按钮,才能继续播放。随手Google了一下,发现了这IofoQ的一篇报道:Chrome 45将不再自动播放Flash。

请问大家是如何解决这个问题的?如何让Flash播放器自动播放视频?

以下内容更新与2016年1月21日11:00
下面是在StackOverFlow上搜的相似问题的回答:

  • The Flash Content and the page are loaded from the same domain.
    Unknown Width and Height of the Flash Object ie when Chrome gets the width and height as 0 or less than 0.

  • The Flash Content is whitelisted by the user in Chrome Settings.

  • The Width and Height of the Flash Object are less than or equal to 5 each, considering the content to be Tiny and essential.

  • The Width and Height of the Flash object are equal or greater than 398x298.

  • The Aspect Ratio of the content is 16:9, (with an allowed deviation of 0.01) AND the width*height area is at least 120K.

题主给出了下面几个解决方法:

  1. 使用ExternalInterface

  2. 初始化播放器尺寸大于398x298,然后使用transform: scale()

  3. In Flash - stage.frameRate returns correct value (it's not set to 0 to pause the SWF for instance)

我尝试了第2种解法,但是这样会造成Flash视频卡顿。其它解法不会。。。囧!

阿神
阿神

闭关修行中......

全部回复(2)
ringa_lee

Google 到了 Chrome 官方论谈的一篇帖子。帖子把 Chromium 的源码都给扒出来了,最终给出了一个解决办法:

  • 跨站(Cross-origin)的 flash 的宽度至少是 398,高度至少是 298,否则会被认为是不重要的 flash

  • flash 内容的宽度比为 16:9 的 flash 会被当作重要的,因此可以自动播放。

你的视频好像是高度不够。

相关的源码如下:

// Content below this size in height and width is considered "tiny".
// Tiny content is never peripheral, as tiny plugins often serve a critical
// purpose, and the user often cannot find and click to unthrottle it.
const int kTinyContentSize = 5;

// Cross-origin content must have a width and height both exceeding these
// minimums to be considered "large", and thus not peripheral.
const int kLargeContentMinWidth = 398;
const int kLargeContentMinHeight = 298;

// Mark some 16:9 aspect ratio content as essential (not peripheral). This is to
// mark as "large" some medium sized video content that meets a minimum area
// requirement, even if it is below the max width/height above.
const double kEssentialVideoAspectRatio = 16.0 / 9.0;
const double kAspectRatioEpsilon = 0.01;
const int kEssentialVideoMinimumArea = 120000;

完整的参见这里

阿神

按照google 的说法是,将不会对flash广告进行自动播放。 google 应该有技术去识别。 如果你的视频不是广告,那应该可以自动播放的

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号