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.