[LayaAir 1.0]个人笔记:失焦或静音状态下播放背景音乐无效的解决方案
SoundManager.playSound=function(url,loops,complete,soundClass,startTime){修改SoundManager的playSound方法如上。
(loops===void 0)&& (loops=1);
(startTime===void 0)&& (startTime=0);
if(!url) return null;
SoundManager._recoverWebAudio();
url=URL.formatURL(url);
if (url!=SoundManager._tMusic){
if (Render.isConchApp){
var ext=Utils.getFileExtension(url);
if (ext !="wav" && ext !="ogg"){
alert("The sound only supports wav or ogg format,for optimal performance reason,please refer to the official website document.");
return null;
}
}
if(!SoundManager._isActive || SoundManager._muted || SoundManager._soundMuted){
return null;
}
};
var tSound;
if (!Browser.onMiniGame){
tSound=Laya.loader.getRes(url);
}
if (!soundClass)soundClass=SoundManager._soundClass;
if (!tSound){
tSound=new soundClass();
tSound.load(url);
if (!Browser.onMiniGame){
Loader.cacheRes(url,tSound);
}
};
var channel;
channel=tSound.play(startTime,loops);
if (!channel)return null;
if(url == SoundManager._tMusic){
if(!SoundManager._isActive || SoundManager._muted || SoundManager._musicMuted){
channel.pause();
SoundManager._blurPaused=true;
}
}
channel.url=url;
channel.volume=(url==SoundManager._tMusic)? SoundManager.musicVolume :SoundManager.soundVolume;
channel.completeHandler=complete;
return channel;
}
原因:引擎会在失焦或者静音状态下不创建SoundChannel对象,等到上一个背景音乐播放完成后,在失焦或静音状态下无法继续播放下一个背景音乐。
没有找到相关结果
已邀请:
要回复问题请先登录
1 个回复
Laya_Xq
赞同来自: