Mp3 audio in the Android Assets folder fails to play from a signed and zip-aligned APK

ⅰ亾dé卋堺 提交于 2019-12-01 10:35:37

The reason your app works when run from within Eclipse (or MOTODEV Studio) on debug is it is not going through the full path that occurs on export. I don't have the SDK build process chart in front of me, but there is one out there. I'm sure a bit of probing the Ant scripts will expose what is going on.

I say this because there's nothing MOTODEV Studio does different from Eclipse wrt the build process. While there is a separate "Export with MOTODEV Studio" menu item, all that's happening there is a couple of fields are being pre-populated with information as a convenience and access to your certificate store. Otherwise, the export process is the same as Eclipse+ADT (which is what it is).

The problem seems to be related to the mediaPlayer.prepare() method in the MusicFactory.java of AndEngine. I've just comment out line 91 (as in the following code snipet) and the MP3 resource was loaded without any exceptions. I think the same can be done with the asset loading method.

public static Music createMusicFromResource(final MusicManager pMusicManager, final Context pContext, final int pMusicResID) throws IOException {
        final MediaPlayer mediaPlayer = MediaPlayer.create(pContext, pMusicResID);
        **//mediaPlayer.prepare();**

        final Music music = new Music(pMusicManager, mediaPlayer);
        pMusicManager.add(music);

        return music;
    }

You could put the audio-files in the "RAW" folder and play them via:

mPlayer2= MediaPlayer.create(this, R.raw.MUSICTAG);
mPlayer2.start();

This way, there should be no problems with compression.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!