Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getFileDescriptor returns null while reading mp3 files from the expansion files

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 ?

like image 532
hacker Avatar asked Jan 15 '13 09:01

hacker


1 Answers

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

AssetFileDescriptor asd = expansionFile.getAssetFileDescriptor("main.1.com.mypackage.app/mysong.mp3");
like image 59
hacker Avatar answered Oct 19 '22 18:10

hacker