zmxv / react-native-sound

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

Plugging in headphones causes sound to play #394

Open kevinEsherick opened 6 years ago

kevinEsherick commented 6 years ago

Im having an error where plugging in a pair of headphones causes my sound to play, regardless of where in the app I am or what I'm doing, and it's only supposed to play on a certain screen after a specific sequence of events. My code is basically pulled straight from the example. This is on iOS (haven't tested on Android) and is happening in both debug and release modes. It only happens after the sound has been played before, and then any time I plug in headphones it fires again. Anyone else experiencing this? Any ideas?

kevinEsherick commented 6 years ago

Came up with a fix but this is still unexpected behavior. To fix it I declare the this.sound = new Sound (...) in the componentWillMount method then release the sound as a callback to when it is played. Releasing in componentWillUnmount does not work for some reason. Also if you want to play it a second time, call release as success callback to sound.play() and then also declare something like this.sound2 = new Sound(same sound file) in that callback and use this sound later. Strange bug but if anyone has this problem hopefully this helps. Leaving open for now cuz it's still a bug that needs addressing

schumannd commented 6 years ago

I might have experienced this as well. Randomly having two sounds play at the same time or sounds starting somewhere in the app. I didn't manage to reproduce it consistently yet, but it is a pretty big issue.

Using: react-native-cli: 2.0.1 react-native: 0.51.0 react-native-sound : 0.10.5

Only appeared on iPhone 5 / 5s so far.

vikeen commented 6 years ago

This also applies to be issue #445. If I play the audio, pause, and then insert headphones it begins playing again.

@schumannd - In my case, the audio is a few minutes long and is consistently reproduced

schumannd commented 6 years ago

@vikeen sounds more similar to #423. I already use Sound.setCategory('Playback');, so I have a different Issue.