问题
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