remigallego / react-native-use-sound

useSound 🔊 A React Native hook for playing sounds 🔊
MIT License
82 stars 9 forks source link

Hook not working on iOS #4

Open pierroo opened 2 years ago

pierroo commented 2 years ago

Is there any known issue on iOS ?

I am using the code below:

export const AudioChat = ({ src }) => {
  const [play, pause, stop, data] = useSound(src);
  const handlePlay = () => {
    if (data.isPlaying) pause()
    else play()
  }

  return (
    <TouchableOpacity onPress={handlePlay}>
        {data.isPlaying ?
          <Icon size={24} name="pause"  />
          :
          <Icon size={24} name="play-outline" />
        }
    </TouchableOpacity>
  )
}

Which works perfectly on Android, however on iOS when pressing it toggles to "isPlaying" icon, but no sound can be heard, and it never turns back to !isPlaying

I'm using a remote source, again it works fine on android and the remote source is correct. ( latest version of this plugin and react-native )

pierroo commented 2 years ago

By any chance if you happen to pass by here, can you let me know @remigallego if this hook is also meant to work on iOS?

remigallego commented 2 years ago

@pierroo Thanks for the feedback. The library should work with iOS out of the box. Can you let me know which iOS version you're using?

pierroo commented 2 years ago

Hi @remigallego thanks for passing by! I am using iOS 15.1; I am using your hook exactly as it is mentioned in your docs; and again it works fine on Android so I really don't understand why nothing happens (beside the state toggle of icon)

Additional info:

When doing a console.log(sound) in the "play" function I get the following:

{"_duration": -1, "_filename": "source_fake", "_key": 33, "_loaded": false, "_numberOfChannels": -1, "_numberOfLoops": 0, "_pan": 0, "_pitch": 1, "_playing": false, "_speed": 1, "_volume": 1, "registerOnPlay": [Function anonymous]}

I believe the "duration: -1" might be the issue? Is there anything else that could help with this?

Random thought: could iOS require any specific permission to play remote sound? from their info.plist or whatever?

pierroo commented 2 years ago

In case you wondered, I am still facing the issue and unable to find a fix. Would you mind sharing your react-native-sound version with which it works? Might be the latest release that breaks it?