cocos3.13.1版本引擎,无法播放背景音乐

09-22 15:27:17.110 3781-3799/gianghoky.game.mobo E/Cocos2dxMusic: error: assets/sound/music/Login.aac
java.io.FileNotFoundException: assets/sound/music/Login.aac
at android.content.res.AssetManager.openAssetFd(Native Method)
at android.content.res.AssetManager.openFd(AssetManager.java:332)
at org.cocos2dx.lib.Cocos2dxMusic.createMediaplayer(Cocos2dxMusic.java:253)
at org.cocos2dx.lib.Cocos2dxMusic.preloadBackgroundMusic(Cocos2dxMusic.java:86)
at org.cocos2dx.lib.Cocos2dxHelper.preloadBackgroundMusic(Cocos2dxHelper.java:231)
at org.cocos2dx.lib.Cocos2dxRenderer.nativeRender(Native Method)
at org.cocos2dx.lib.Cocos2dxRenderer.onDrawFrame(Cocos2dxRenderer.java:104)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1523)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
09-22 15:27:17.110 3781-3799/gianghoky.game.mobo E/Cocos2dxMusic: playBackgroundMusic: background media player is null

现在只测试了aac格式的,以前在3.7版本是可以的,突然脑子抽风想更新到3.13.1,就这样咯

09-22 17:31:51.954 3162-3179/gianghoky.game.mobo E/Cocos2dxMusic: error: assets/sound/music/Login.ogg
java.io.FileNotFoundException: assets/sound/music/Login.ogg
at android.content.res.AssetManager.openAssetFd(Native Method)
at android.content.res.AssetManager.openFd(AssetManager.java:332)
at org.cocos2dx.lib.Cocos2dxMusic.createMediaplayer(Cocos2dxMusic.java:253)
at org.cocos2dx.lib.Cocos2dxMusic.preloadBackgroundMusic(Cocos2dxMusic.java:86)
at org.cocos2dx.lib.Cocos2dxHelper.preloadBackgroundMusic(Cocos2dxHelper.java:231)
at org.cocos2dx.lib.Cocos2dxRenderer.nativeRender(Native Method)
at org.cocos2dx.lib.Cocos2dxRenderer.onDrawFrame(Cocos2dxRenderer.java:104)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1523)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
09-22 17:31:51.954 3162-3179/gianghoky.game.mobo E/Cocos2dxMusic: playBackgroundMusic: background media player is null

用OGG格式的背景音乐也不行

CocosDenshion::SimpleAudioEngine::getInstance()->playBackgroundMusic(m_strBackMusicPath.c_str(), bLoop);

播放背景音乐的接口,这个坑有点大,所以继续换到3.7版本了,等新版本稳定后,再来用新版本吧

可以用3.12 我正在用 声音没问题

换了声音的引擎,用AudioEngine来播放,发现缓存总是失败,但是直接调用play2d是可以播放背景音乐的。

@dumganhar 看一下吧。

目测是在apk中没有找到aac文件,能发一个apk来测试一下么?

AudioEngine在3.13中的缓存机制是根据文件大小,如果文件很大,默认是不缓存的。

可以修改对应的数值做调整:

cocos/audio/android/AudioPlayerProvider.cpp

static AudioFileIndicator __audioFileIndicator[] = {
        {"default", 128000}, // If we could not handle the audio format, return default value, the position should be first.
        {".wav",    1024000},
        {".ogg",    128000},
        {".mp3",    160000}
};

http://qmwgres.zs-e.com/music.zip 这个zip文件中是我测试用的aac音乐

收到,谢谢,我确认一下。

@448223155,我这用cocos2d-x-3.13.1测试了你的两个aac音频,用SimpleAudioEngine和AudioEngine都可以正常播放的。
从你的日志看,你应该是没有打包成功,导致没找到对应的aac文件。
需要的话,可以发我apk,我这里确认一下。