在页面中,有标签
在页面有一个定时循环的script,执行下面的逻辑
function play(){
document.getElementById("sound").src = "";
}
问题是,当ie最小化后,就不会执行这个逻辑播放音乐了。
我的理解是,当页面最小化后,ie的时间即时是不是会暂停?
这个可以怎样处理呢,能达到在ie最小化后,也同样播放的效果。
[b]问题补充:[/b]
只能在这里说么?没找到可以引用回答的呢?
atian25的
只能改用嵌入flash的方式来播放
因为播放的内容是和业务相关的,即
document.getElementById("sound").src = "";
这个有时候播放1.mp3,有时候播放2.mp3
所以,即使用flash来播放,一定需要传递参数到flash中。这个逻辑怎样组织呢?
[b]问题补充:[/b]
多谢atian25的回答
我现在的逻辑是通过setInterval("play()",this.refreshTime); 播放,且在播放前根据业务判断结果播放对应的mp3.
即,我理解的问题是,假如setInterval中的play都不执行了?那即使用
soundSwf.playSound(soundUrl,2);
也不能播放吧?这个时候没有调用者了。
是否这样可以,将setInterval的循环放到flash中,即使用flash作为一个调用者。
在ie被最小化后,flash中的定时循环还在继续。在flash的循环中,调用js,查询相应的逻辑结果,并将对应的应该播放的mp3文件名返回。
此时,再在flash中播放??
[b]问题补充:[/b]
这个问题的关键是用bgsound,
1.只是ie only
这个是说明白了。
刚查了下,
使用< embed>标签
它的使用方法与第一种基本一样,只是第一步的代码提示框里不要选择gbsound,改而选择embed即可。然后再选择它的属性进行相应的设置
似乎使用embed也能达到效果??
[b]问题补充:[/b]
刚最新测试了下,发现
bgsound在ie7下面不存在最小化后不能播放的问题。ie6存在
看[url]http://atian25.iteye.com/blog/440864[/url]
只能改用嵌入flash的方式来播放
js和as是可以通信的嘛...
摘抄部分以前的代码:
[code="javascript"]
var soundUrl = alarmCount>0 ? 'alarm.mp3' : 'event.mp3';
soundSwf.playSound(soundUrl,2);
[/code]
[code="actionscript"]
//SoundSwf.as
package {
import flash.display.*;
import flash.events.*;
import flash.media.Sound;
import flash.net.URLRequest;
import flash.external.ExternalInterface;
import flash.utils.*;
public class SoundSwf extends Sprite{
//from aswing's lib
private var map:HashMap = new HashMap();
public function SoundSwf():void{
if (ExternalInterface.available){
ExternalInterface.addCallback("playSound", this.playSound);
}
}
public function playSound(url:String,count:int):void{
var s:Sound;
if(!map.containsKey(url)){
s = new Sound();
map.put(url,s);
s.addEventListener(Event.COMPLETE,function(e:Event):void{
var localSound:Sound = e.target as Sound;
localSound.play(0,count);
});
s.addEventListener(IOErrorEvent.IO_ERROR, function(e:IOErrorEvent):void{ExternalInterface.call("alert", e);});
s.load(new URLRequest(url));
}else{
s = map.get(url) as Sound;
s.play(0,count);
}
}
}
}
[/code]
逻辑端在js还是as都无所谓.
这个问题的关键是用bgsound,
1.只是ie only
2.看名字理解,就是bg's sound,你都最小化了,当然没得了.
所以要通过swf来播放声音.
至于是js来轮询还是as,都随便
非ie浏览器似乎对embed支持不好