Failed to convert to modern format file descriptor

Viewed 529

This is my codes:

if (myAudio.exists()) {
            mp.reset();
            //mp.setDataSource(getContext(), Uri.fromFile(myAudio));
            FileInputStream is = new FileInputStream(myAudio);
            FileDescriptor fd = is.getFD();
            mp.setDataSource(fd);
            is.close();
            mp.setOnErrorListener(this);
            mp.setOnPreparedListener(this);
            mp.prepareAsync();
            btnPlay.setImageResource(R.drawable.pause);
        } else {
            btnPlay.setImageResource(R.drawable.play);
            errorGot = errorGot + 1;
        }

I have tried using mp.setDataSource from Uri, and using FileDescriptor, but both got the same error:

  Failed to convert to modern format file descriptor
  java.io.IOException: Input file descriptor already original
    at android.provider.MediaStore.getOriginalMediaFormatFileDescriptor(MediaStore.java:943)
    at android.os.FileUtils.convertToModernFd(FileUtils.java:1470)
    at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1271)
    at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1254)

Any help, please? Thank you.

1 Answers

i have alternative solution. use physical device instead of emulator. my emulator android-arm64 • Android 12 (API 31) (emulator) my physical device android 10 () this error just came from emulator but i still looking how to solve and why .

Related