-3

I am working on a music app. I have been able to get all audio files on my device external storage and add them to a recycler view, but there are some corrupt files on the device. I want to add only the non-corrupt files and filter out the corrupt ones. I have tried a couple of ways, but none seems to work.

  1. I tried usin' the mediaPlayer.prepare() method to prepare the audio file and then catch an IllegalStateException, but it was in vain.
  2. I also tried using FileOutputStream to read the audio file and catch an exception, still no positive result.
  3. I tried usin' the Iterator class to iterate through the files then with Uri.parse(song.getPath) chek if it's null and if null remove from the list, still didn't work.

PLEASE HELP...

El.60I
  • 9
  • 1
  • 1
    What exactly happens if you do try to use a corrupt file? Where does the failure occur, and what does this error look like? – Hovercraft Full Of Eels Aug 24 '23 at 20:53
  • It happens when I try to start the media player. I get a nullpointerexception. I could catch the exception from there directly and fix the crash tho', but I do not want to do that, I want to filter out all corrupt files from scratch , before the recyclerview gets populated – El.60I Aug 24 '23 at 21:19
  • 1
    Then ***that*** is what you need to do a null check on! That variable that causes the NPE is null (whatever variable it may be -- and it is your job to find out), and so check for that and exclude the related file. – Hovercraft Full Of Eels Aug 24 '23 at 21:23
  • 1
    Either that or use an [Optional](https://docs.oracle.com/en/java/javase/14/docs/api/java.base/java/util/Optional.html). – Hovercraft Full Of Eels Aug 24 '23 at 21:32

0 Answers0