From ada1d1dfe817506f1cb86e2cd4268be0c5d8c184 Mon Sep 17 00:00:00 2001 From: ViusualSJ Date: Wed, 11 May 2016 17:24:14 +0800 Subject: [PATCH] audio search path (android) --- .../js-bindings/script/jsb_cocos2d.js | 20 +++++++++++++++++++ .../CocosDenshionTest/CocosDenshionTest.js | 3 --- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/cocos/scripting/js-bindings/script/jsb_cocos2d.js b/cocos/scripting/js-bindings/script/jsb_cocos2d.js index 691c917064..114280b023 100644 --- a/cocos/scripting/js-bindings/script/jsb_cocos2d.js +++ b/cocos/scripting/js-bindings/script/jsb_cocos2d.js @@ -2626,6 +2626,26 @@ _p.setDisabledSpriteFrame = function(frame) { cc.MenuItemToggle.prototype.selectedItem = cc.MenuItemToggle.prototype.getSelectedItem; +// playMusic searchPaths +if (cc.sys.os === cc.sys.OS_ANDROID && cc.audioEngine) { + cc.audioEngine._playMusic = cc.audioEngine.playMusic; + cc.audioEngine.playMusic = function () { + var args = arguments; + var searchPaths = jsb.fileUtils.getSearchPaths(); + var path = args[0]; + searchPaths.some(function (item) { + var temp = item + '/' + path; + var exists = jsb.fileUtils.isFileExist(temp); + if (exists) { + path = temp; + return true; + } + }); + args[0] = path; + cc.audioEngine._playMusic.apply(cc.audioEngine, args); + }; +} + // // LabelTTF API wrappers // diff --git a/tests/js-tests/src/CocosDenshionTest/CocosDenshionTest.js b/tests/js-tests/src/CocosDenshionTest/CocosDenshionTest.js index bb72b4553b..56f1bcfa1f 100644 --- a/tests/js-tests/src/CocosDenshionTest/CocosDenshionTest.js +++ b/tests/js-tests/src/CocosDenshionTest/CocosDenshionTest.js @@ -232,9 +232,6 @@ var soundId = null; var playMusic = function () { cc.log("play background music"); var musicFile = MUSIC_FILE; - if (cc.sys.os == cc.sys.OS_ANDROID) { - musicFile = "res/"+musicFile; - } audioEngine.playMusic(musicFile, false); };