zmxv / react-native-sound

React Native module for playing sound clips
MIT License
2.79k stars 748 forks source link

undefined is not an object ('evaluating 'this.state.trackInfoArray[0].path') #608

Closed wezzy-web closed 5 years ago

wezzy-web commented 5 years ago

:beetle: Description

:beetle: What have you tried?

:beetle: Please post your code:

componentWillMount() {
    MusicFiles.getAll({
      id: true, // get id
      artist: true, // get artist
      duration: true, // get duration
      genre: true, // get genre
      title: true, // get title
      fileName: true, // get file name
      minimumSongDuration: 1000,// get track has min duration is 1000 ms (or 1s)
      path: true 
    }).then(tracks => {
      let trackInfoArray = [];
      for (let i = 0; i < tracks.length; i++) {
        if (tracks[i]) {
          let trackInfo = new Trackinfo(tracks[i]);
          trackInfoArray.push(trackInfo);
        }
      }
      this.setState({ trackInfoArray });
      ToastAndroid.show(`There are ${trackInfoArray.length} tracks`, ToastAndroid.SHORT);
    }).catch(error => {
      ToastAndroid.show(`${error.message}`, ToastAndroid.SHORT);
    });

 var song = new Sound(this.state.trackInfoArray[0].path,'', 
  (error) => console.log(song.isLoaded())); 
 if (song.isLoaded()) 
  { song.setVolume(1); 
    song.play((success) => { if (success) 
      { console.log('successfully finished playing'); } 
      else { console.log('playback failed due to audio decoding errors'); } 
    });
  }

:bulb: Possible solution

Is your issue with...

Are you using...

Which versions are you using?

Does the problem occur on...

If your problem is happening on a device, which device?

wezzy-web commented 5 years ago

please help me

paulmelnikow commented 5 years ago

You'll see that this.state.trackInfoArray[0].path is in your React code, not in react-native-sound. It's out of scope of what can be done here. I'd suggest posting on Stack Overflow.

wezzy-web commented 5 years ago

okay i do thank you