本文介绍了如何检测Chrome的“点击播放” Flash阻止功能目前处于活动状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Chrome浏览器点击播放功能的跟踪状态

您如何检测到Flash插件已被暂时禁用,或者反过来检测到它已被由于Chrome浏览器的点击播放功能而被启用?

背景



播放功能可以检测到不明显的插件并暂停播放。 Chrome会在插件上显示播放按钮,用户可以点击播放按钮来激活插件。 (参考:)

下面是它的动作截图(注意白色按钮):

您可以在此屏幕截图中看到它暂停了视频播放器(右栏)。该视频播放器具有覆盖基于Flash的视频播放器的基于HTML5的控件。所以,用户无法单击播放按钮,因为整个SWF被基于HTML5的播放/暂停控件有目的地覆盖。



我需要的是通过点击播放功能检测SWF何时暂停,以便我可以禁用控件并使SWF交互。

我试过的所有方法




  1. 虽然SWF暂停,但code> ExternalInterface 仍然可用。它实际上响应像它正在播放,并不会返回一个错误。

  2. 在JavaScript中 - 将嵌入的< object> 的大小更新为> 700x400px。 点击播放不会暂停这种尺寸的SWF。所以,我尝试使用 -webkit-transfor:scale(0.5)来使用CSS将其缩放回所需的大小。 Chrome计算最终呈现的大小,并暂停SWF。

  3. 在Flash中 - stage.frameRate 返回正确的值(它没有设置为0暂停SWF的例子)






在写这个问题我发现回答,决定在这里发帖,以防其他人需要帮助解决这个问题。为解决Chrome的点击播放限制问题,请从与您网站相同的域名和协议中加载您的SWF文件。 / p>




您可以使用AS3 ThrottleEvent 来检测SWF何时

  // AS3代码
import flash.events.ThrottleEvent;
import flash.external.ExternalInterface;

stage.addEventListener(ThrottleEvent.THROTTLE,onThrottleEvent);

private function onThrottleEvent(e:ThrottleEvent){
ExternalInterface.call(onThrottleEvent,e.state); //调用javascript函数

code $

$ b $你可以设置一个 ExternalInterface 调用来跟踪JavaScript中的这种状态,在JavaScript中根据是否受到限制来管理SWF的 z-index


  // JS代码
var IS_THROTTLED = false;

window.onThrottleEvent = function(throttleState){
IS_THROTTLED =(throttleState ===throttle);
}


Tracking state of Chrome's Click-to-play feature

How do you detect that a Flash plugin has been temporarily disabled, or, conversely, detect that it has been enabled due to Chrome's "click-to-play" feature?

Background

Chrome's new "click-to-play" feature detects plugins that are not visibly significant and pauses them. Chrome displays a "play" button over the plugin, a user may click the "play" button to activate the plugin. (reference: https://productforums.google.com/forum/#!topic/chrome/xPcpRBzyPcc)

Here's a screenshot of it in action (notice white play buttons):

You can see in this screen shot that it has paused a video-player (right column). That video player has HTML5-based controls overlaying a Flash-based video player. So, there's no way for a user to click the play-button as the entire SWF is purposefully covered by HTML5-based play/pause controls.

What I need is to detect when the SWF has been paused by the "click-to-play" feature so I can disable the controls and make the SWF interactive.

What I've tried

  1. In JavaScript - All methods exposed via ExternalInterface are still available though the SWF is paused. It actually responds like it's playing and does not return an error.
  2. In JavaScript - Update the size of the embedded <object> to > 700x400px. "Click-to-play" does not pause a SWF of this size. So, I tried using -webkit-transfor: scale(0.5) to use CSS to scale it back to desired size. Chrome calculates the final rendered size and pauses the SWF regardless.
  3. In Flash - stage.frameRate returns correct value (it's not set to 0 to pause the SWF for instance)


In writing up this question I found an answer, decided to post here anyways in case others need help with this issue.

解决方案

To circumvent the Chrome click-to-play throttling, load your SWF from the same domain and protocol as your site.


You can use the AS3 ThrottleEvent to detect when the SWF has been throttled.

// AS3 code
import flash.events.ThrottleEvent;
import flash.external.ExternalInterface;

stage.addEventListener(ThrottleEvent.THROTTLE, onThrottleEvent);

private function onThrottleEvent(e:ThrottleEvent) {
    ExternalInterface.call("onThrottleEvent", e.state); // call javascript function
}

You can setup an ExternalInterface call to keep track of this state in JavaScript, in JavaScript manage z-index of your SWF based on if it's throttled or not.

// JS Code
var IS_THROTTLED = false;

window.onThrottleEvent = function (throttleState) {
  IS_THROTTLED = (throttleState === "throttle");
}

这篇关于如何检测Chrome的“点击播放” Flash阻止功能目前处于活动状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 06:17