cocos2d / cocos2d-x

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.
https://www.cocos.com/en/cocos2d-x
18.24k stars 7.06k forks source link

cc.audioEngine does not consider cc.loader.resPath on Android #19071

Open fleon opened 6 years ago

fleon commented 6 years ago

Steps to Reproduce:

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.

PatriceJiang commented 6 years ago

cc.loader.resPath is not used for audios. https://github.com/plter/Cocos2d-x-js-3-docs/blob/master/Cocos2d-JS/Features/cc-loader/en.md#respath