0

I have been developing an App which need to play sounds and have large set of sounds files in .wav format that boast arounds near 1GB size. I have followed the official documentation for making the Expansion file.

First i made a .zip file with 0 compressions, all .wav files are under that files (without any subfolder. that is main.1.package contains all the sounds file).Then i renamed the .zip folder into .obb. After that i put that .obb file inside the apps folder under shared storage obb folder (com.moinul.app is my package name, so the folder name was it, also the expansion file were named main.1.com.moinul.app.obb )

Problem is when i try to read the files from my expansion files i get null pointer exceptions:

try
    {
        String param = (String) v.getTag();

        ZipResourceFile expansionFile = APKExpansionSupport.getAPKExpansionZipFile(context, 1, 0);
        AssetFileDescriptor fd = expansionFile.getAssetFileDescriptor("p25_1.wav");

        MediaPlayer mPlayer = new MediaPlayer();
        mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        mPlayer.setDataSource(fd.getFileDescriptor());
        mPlayer.prepare();
        mPlayer.start();
    }
    catch (Exception e)
    {
        Log.w(TAG,  e.getMessage() + "");
        e.printStackTrace();
    }

I get exceptions saying that fd is null. Any help would be appreciated. Thanks

aaa111
  • 345
  • 5
  • 14

3 Answers3

0

Try use: AssetFileDescriptor fd = expansionFile.getAssetFileDescriptor("assets/p25_1.wav");

Dungnbhut
  • 176
  • 5
0

Try `public class Test extends Activity {

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);


    String TAG = "Test";
    Context context = this;
    try {
        MediaPlayer mediaPlayer = new MediaPlayer();

        ZipResourceFile expansionFile = APKExpansionSupport.getAPKExpansionZipFile(context, 1, 0);
        AssetFileDescriptor assetFileDescriptor = expansionFile.getAssetFileDescriptor("assets/p25_1.wav");

        if (assetFileDescriptor != null) {
            final FileInputStream fis = assetFileDescriptor.createInputStream();
            if (fis != null) {
                mediaPlayer.setDataSource(fis.getFD());
                fis.close();
                mediaPlayer.prepare();
                mediaPlayer.start();
            } else {
                Log.w(TAG, "/fis: null");
            }
        }

    } catch (Exception e) {
        Log.w(TAG, e.getMessage() + "");
    }
}

}`

Dungnbhut
  • 176
  • 5
  • If my code not working maybe you should check file expansion. I hope it can help you. http://stackoverflow.com/questions/18929273/how-to-create-obb-file-as-main-apk-expansion-file-using-jobb-tool – Dungnbhut May 12 '17 at 07:07
0

Ok so it worked finally. After changing into :

 AssetFileDescriptor fd = expansionFile.getAssetFileDescriptor("Sounds/p25_1.wav");

Its working now. Its weird that i had to add Sounds, which was the folder name before compress (i actually compressed this folder and all .wav are under it). I think the compressor made another subfolder inside the .zip.

Anyway thanks for the help.

aaa111
  • 345
  • 5
  • 14