SWFObject
我的网页上有一个小问题。行为是,当 Flash 播放器被另一个选项卡覆盖或最小化时,它不会开始播放音频,直到选项卡再次获得焦点并可见。它使用SWFObject
来自http://code.google.com/p/swfobject/的 2.1 版本。为了验证这种行为,加载页面,在 5 秒内将其最小化,您会注意到代码中的代码beginPlay
更改了页面的标题。这发生在音频应该开始播放之后,但直到浏览器再次获得焦点才会开始。这是复制问题的代码示例:
<html>
<head>
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript" src="audio-player-uncompressed.js"></script>
<script>
function doLoad() {
AudioPlayer.setup("player2.swf", {
width: "350px",
animation: "no",
autostart: "yes",
loop: "yes",
buffer: "5",
initialvolume: 100,
});
AudioPlayer.embed("flashPlayer");
}
function beginPlay(){
setTimeout(function(){
AudioPlayer.embed("flashPlayer", {
soundFile: "test.mp3"
});
document.title = "code after the flash player has executed."
}, 5000);
}
</script>
</head>
<body onload="doLoad();">
This demonstration is to show how either WP Audio Player or SWFObject
does not build the flash player while the browser is minimized.
<br><br>
<a href="javascript:beginPlay();">click this and minimize quickly.</a><br>
<div id="flashPlayer"></div>
</body>
</html>