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

前端 未结 3 920
庸人自扰
庸人自扰 2021-01-14 20:13

I am loading mp3 files to play in an Android game based on AndEngine. When I package my game as an APK, mp3 audio in the assets folder throws the error \"can not be opened a

3条回答
  •  独厮守ぢ
    2021-01-14 20:30

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

提交回复
热议问题