cocos2d实现语音_cocos2d-x之3.8音频管理

新版本引擎添加了音频预加载功能,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()在切场景更换背景音乐时使用,先停,再播。。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值