cinder92 / react-native-get-music-files

React Native package to get music files from local and sd for iOS and Android
MIT License
131 stars 65 forks source link

Something get wrong with musicCursor Error #55

Closed ThalKod closed 5 years ago

ThalKod commented 5 years ago

I'm Trying to use the module on Android, but i'm having Something get wrong with musicCursor Unable to fetch any musics files...

Drazail commented 5 years ago

@ThalKod

Please provide more information likr:

ThalKod commented 5 years ago

@Drazail I'm using RN 0.59.8, with react-native-get-music-files@2.1.0 running on Android API 28. This is how i'm trying to use it after installation:

...

import MusicFiles from "react-native-get-music-files";

...
 useEffect(() => {
    navigation.setParams({ handleModal });
    fetchMusic();
  }, []);

  const fetchMusic = async () => {
    const status = await Permissions.request('storage');
    if(status !== "authorized"){
      Alert.alert(
          "We can't access your music",
      );
    }

     MusicFiles.getAll({
      blured : true, // works only when 'cover' is set to true
      artist : true,
      duration : true, //default : true
      genre : true,
      title : true,
      cover : true,
      minimumSongDuration : 10000,
      fields : ['title','albumTitle','genre','lyrics','artwork','duration']
    }).then(tracks => {
       console.log(tracks)
     }).catch(error => {
       console.log("error",error);
     })

  };
...

I'm getting this :

Screen Shot 2019-08-01 at 3 28 56 PM Screen Shot 2019-08-01 at 3 27 03 PM
Drazail commented 5 years ago

@ThalKod is there any music files on the device?

ThalKod commented 5 years ago

@Drazail I Added two music files(.mp3) on the device, they are located in the Downloads/ folder , but i still have the same error... Any idea what might be the problem ?

Drazail commented 5 years ago

@ThalKod

I haven't developed getMusicFiles class, however after taking a brief look, this error seems to be thrown when the corresponding database table is empty.

Try rebooting the device and check if the problem goes away.

ThalKod commented 5 years ago

@Drazail Thanks, I reboot the app and it's working(fetched the two music files), but i can see two issues with that:

Drazail commented 5 years ago

@ThalKod

dimbslmh commented 4 years ago

You'd expect "Something get wrong with musicCursor" to go into the catch block, but it doesn't. So basically for now we need to check if (typeof tracks === 'object') { return tracks } else { return [] }