zmxv / react-native-sound

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

Phone hangs, camera crashes after playing sound #665

Closed HishamMubarak closed 2 years ago

HishamMubarak commented 4 years ago

:beetle: Description I have been having this issue in my app for past 1 year. Received a lot of 1 star rating, mostly from Redmi users, from users saying their mobile crashes a lot after installing my app. I have tried upgrading to latest react native version at the time, building the app from entirely from new project to make sure it wasn't my android misconfiguration etc. Anyways, I spent last few days debugging the issue and found out removing this package solved everything! Another weird issue is, this issue was only reported from Redmi devices. Redmi Note 4, Redmi Note 5 etc.

:beetle: What is the observed behavior? User opens the app, goes through a few screens where some sounds are played and then exists the app. Then, after a few minutes, their camera module wont work. Either their camera will not start, or the camera app will start but the entire view will be black filled and nothing else.

This issue persists even when the app is in background mode and also when it is killed and removed from the app drawer.

:beetle: What is the expected behavior? Well, the user's mobile should work as expected.

:beetle: Please post your code: I have not been able to pinpoint to a specific line of code. I have come to the conlusion that it is caused only after playing a few sounds in the app.

The below is what I guess the culprit is

2020-04-02 21:50:16.151 10038-10100/? E/MediaPlayer-JNI: JNIMediaPlayerFactory: bIsQCMediaPlayerPresent 0
2020-04-02 21:50:16.152 10038-10100/? E/ExtMediaPlayer-JNI: env->IsInstanceOf fails
2020-04-02 21:50:16.152 10038-10100/? E/MediaPlayer-JNI: JNIMediaPlayerFactory: bIsQCMediaPlayerPresent 0

:bulb: Does the problem have a test case? I have tried that and it doesn't show up in my mobile device. Also just playing a single file hasn't caused any problems. Only after user uses the app for a few minutes, going through various screens.

:bulb: Is there a workaround? Nope, the only workaround I have found is to comment out this package, until I find a solution here. I checked one other package too, but I guess it has the same problem too, guessing from looking at a few issues in their issues page.

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?

I am not 100% sure if this a conffiguration error on my part, or something wrong with package, or if it something that needs to be fixed from Redmi's side. Anyway, I hope I can find an answer for that here. Please let me know if I need to add any more info into the issue detail.

MikeGlennFWC commented 2 years ago

@HishamMubarak

I've had a similar issue, it took a while to figure out that the sounds were crashing the app.

What i found was that loading sounds like so

const warningSound = new Sound('warning.wav', Sound.MAIN_BUNDLE);
const rejectionSound = new Sound('rejection.wav', Sound.MAIN_BUNDLE);
const goodSound = new Sound('good.wav', Sound.MAIN_BUNDLE);

within a component that re-renders a lot, must tell Android/JVM to load the sound again, which increases memory until the app is culled.

I fixed this my moving the sounds to index.js

also, there is a sound.release(); function that should be called once you're done with the sound to release the resource.

The docs should be a little clearer on this i think.

HishamMubarak commented 2 years ago

@MikeGlennFWC , Sorry for the late reply, and thanks for the update. I have since then moved to another sound package so I was unable to test my code based on your reply. Anyways, I hope everything is working fine now. Closing the issue now.