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); };