tlenclos / react-native-audio-streaming

iOS & Android react native module to play an audio stream, with background support and media controls
MIT License
781 stars 255 forks source link

Is there a way to retrieve the ReactNativeAudioStreaming play status? #131

Open ardboer opened 6 years ago

ardboer commented 6 years ago

Cool module but I also like to know the status of the player to know if it is loading, playing or stopped.

graphee-gabriel commented 6 years ago

You can do it as such:

this.intervalIdStreamState = setInterval(() => {
  ReactNativeAudioStreaming.getStatus((error, info) => {
    let streamStatus
    if (error) {
      streamStatus = 'error'
      console.log(error);
    } else {
      streamStatus = info.status.toLowerCase()
    }
    if (this.state.streamStatus !== streamStatus) {
      console.log('streamStatus stream CHANGED', streamStatus)
      this.setState({ streamStatus }, () => this.onStreamStateChange(streamStatus))
    }
  })
}, 200)