getFileDescriptor returns null while reading mp3 files from the expansion files

こ雲淡風輕ζ 提交于 2019-12-05 20:27:13

问题


I have downloaded and stored the expansion files successfully.But it crashes when i try to play the mp3 inside..

            ZipResourceFile expansionFile = APKExpansionSupport.getAPKExpansionZipFile(getApplicationContext(),
                    1, 0);

            InputStream fileStream = expansionFile.getInputStream("mysong.mp3");
            AssetFileDescriptor asd = expansionFile.getAssetFileDescriptor("mysong.mp3");
            MediaPlayer mediaPlayer = new MediaPlayer();
                    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
                    mediaPlayer.setDataSource(asd.getFileDescriptor(), asd.getStartOffset(), asd.getLength());
                    asd.close();
                    mediaPlayer.prepare();
                    mediaPlayer.start();

Here the logcat says both the inputstream and the file descriptor are null..Can anyone help me ?


回答1:


Finaly it solved.. The file name should be with the full path..

AssetFileDescriptor asd = expansionFile.getAssetFileDescriptor("main.1.com.mypackage.app/mysong.mp3");


来源:https://stackoverflow.com/questions/14334550/getfiledescriptor-returns-null-while-reading-mp3-files-from-the-expansion-files

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