新版本引擎添加了音频预加载功能,jsb绑定了新的AudioEngine音频引擎,实测好用
/**
* Created by Jerry on 15-8-25.
*/
var GameAudio = GameAudio || {
isOpenMusic : true,isOpenEffect : true,playMusic:function(filePath,isLoop){
if(!this.isOpenMusic) return;
jsb.AudioEngine.play2d(this.getAllPath(filePath),isLoop,1.0,jsb.AudioEngine.getDefaultProfile());
},stopMusic:function(filePath){
jsb.AudioEngine.uncache(this.getAllPath(filePath));
},playEffect:function(filePath){
if(!this.isOpenEffect) return;
jsb.AudioEngine.play2d(this.getAllPath(filePath),false,stopEffect:function(filePath){
jsb.AudioEngine.uncache(this.getAllPath(filePath));
},stopAll:function(){
jsb.AudioEngine.stopAll();
},getAllPath:function(filePath){
var path = "";
if(cc.sys.os == "android"){
path = filePath + ".ogg";
}else{
path = filePath + ".mp3";
}
return path;
},getAudioEngine:function(){
return cc.audioEngine;
},preloadSound:function(){
for (var i in res_sound){
if(cc.sys.os == "android"){
jsb.AudioEngine.preload(res_sound[i] + ".ogg",null);
}else{
jsb.AudioEngine.preload(res_sound[i] + ".mp3",null);
}
}
}
}; PS:stopAll()在切场景更换背景音乐时使用,先停,再播。。。