Cocos2d-x is a suite of open-source, cross-platform, game-development tools utilized by millions of developers across the globe. Its core has evolved to serve as the foundation for Cocos Creator 1.x & 2.x.
If I am using cc.loader.resPath, all files loaded by cc.loader are relative to that path, except for all audio (sfx and music) files on Android, in which case they are absolute. Because of that I have to use the below logic in my code:
// resPath is '1x', '2x', '3x' etc
function playEffect(name, repeat = false) {
// todo: bug with android... takes absolute path instead of relative
const dir = cc.sys.os === cc.sys.OS_ANDROID ? 'res' : '..'
return cc.audioEngine.playEffect(`${dir}/sfx/${name}.wav`, repeat)
}
function playMusic(name, loop = false) {
cc.audioEngine.stopMusic()
// todo: bug with android... takes absolute path instead of relative
const dir = cc.sys.os === cc.sys.OS_ANDROID ? 'res' : '..'
cc.audioEngine.playMusic(`${dir}/music/${name}.mp3`, loop)
}
The above code is in JS, but the core issue lies in the C++ version of AudioEngine for Android.
Steps to Reproduce:
If I am using
cc.loader.resPath
, all files loaded bycc.loader
are relative to that path, except for all audio (sfx and music) files on Android, in which case they are absolute. Because of that I have to use the below logic in my code:The above code is in JS, but the core issue lies in the C++ version of AudioEngine for Android.