Search code examples
androidmp3media-playerandroid-mediaplayer

mp3 that plays from SDcard won't play from my app's directory?


I am making an app that will download a zip archive from a location, unzip it and among files are some audio files(mp3) I need to play. The problem is mp3 files do not want to be played??

Now, I didn't C/P any code here since I don't think it might be a problem in the code. I have a Rom Toolbox installed on my phone and with that I copied an mp3 file off my SD card to my app's directory where other audio files are because I thought mp3 might be encoded incorrectly somehow. That is not the case since that same file, when I select it in RomToolbox and select to play it, it won't, but when I select that same file on SDcard it will play??

I don't think it is a matter of access rights since RomToolbox has superuser access.

So how can I get my mp3 files playing even if they are just copied/unzipped to a directory within my app's directory?

Thanks!


Solution

  • Ok, so I found the problem.

    Apparently there is a problem with authorizations, but I am still puzzled why this file browser I have, that has superuser rights, can not play the file when in my directory.

    Anyway, instead of setting the data source for media player from path I use FileDescriptor.

    File tmpFile = new File(GlobalStore.appContext.getFilesDir() + File.separator + "audio" + File.separator + displayedPOI.getAudios().get(0));
    FileInputStream tmpFIS = new FileInputStream(tmpFile);
    mPlayer.setDataSource(tmpFIS.getFD());
    

    This works now.