个人笔记:失焦或静音状态下播放背景音乐无效的解决方案

 
SoundManager.playSound=function(url,loops,complete,soundClass,startTime){
(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;
}
修改SoundManager的playSound方法如上。
原因:引擎会在失焦或者静音状态下不创建SoundChannel对象,等到上一个背景音乐播放完成后,在失焦或静音状态下无法继续播放下一个背景音乐。
 
已邀请:

Laya_Xq

赞同来自:

感谢分享!!!

要回复问题请先

商务合作
商务合作