Chrome浏览器iframe中使用Flash是否自动播放?

2016/10/28 14:40:25 segmentfault.com

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

然后必须要点击一下播放按钮,才能继续播放。

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

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)



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

1、跨站(Cross-origin)的 flash 的宽度至少是 398,高度至少是 298,否则会被认为是不重要的 flash
2、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;



完整的参见这里