getAssetFileDescriptor from ZipResourceFile merges all mp3 in mediaplayer SOLVED

Posted by Jordi on Stack Overflow See other posts from Stack Overflow or by Jordi
Published on 2012-10-10T11:26:00Z Indexed on 2012/10/10 15:37 UTC
Read the original article Hit count: 229

Filed under:
|

I've a program with an Expansion file that stores 4 mp3 in a obb file (zip without compression). I can retrieve the data, but instead of taking the audio file i asked for, it merges ALL audio files in the same AssetFileDescriptor.

---SOLVED--- with the fixes

Support class

  public AssetFileDescriptor getaudio(){
     ZipResourceFile expansionFile = APKExpansionSupport.getAPKExpansionZipFile(c,21,21);
        AssetFileDescriptor afd=null;
        if(take==1) {
            afd = expansionFile.getAssetFileDescriptor("file01.mp3");
        }else if(take==2 {
            afd = expansionFile.getAssetFileDescriptor("file02.mp3");
        } //more els eif ............
        return afd;
  }

In the MediaPlayer class

        AssetFileDescriptor fd = Llistat.getInstance().getAudio();
        mPlayer.setDataSource(fd.getFileDescriptor(), fd.getStartOffset(),fd.getLength());
        mPlayer.prepare();
        fd.close();

My problem was that i directly was returning and using a FileDescriptor, while i was needing the AssetFileDescriptor to take its StartOffset and Length.

© Stack Overflow or respective owner

Related posts about android

Related posts about file-descriptor