Fail to load sound in Android apk. { extra: -2147483648, what: 1 }
Arthur-Noh opened this issue · comments
🪲 Description
I want to make a function that makes a sound when I press a button.
I follow the manual, and it works well on the simulator.
Android: Voice file (beep.mp4) is located in android/app/src/main/res/raw.
iPhone: Add Files to [PROJECTNAME] on xcode.
The iPhone's testFlight works well, too.
However, it doesn't work when I try to use it on a real cell phone.
// The process of making an APK.
./ > npx react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
./ > cd android
./android > ./gradlew assembleRelease
The app will be created normally. But, Fail to load sound.
{ extra: -2147483648, what: 1 }
Could you help me?
🪲 What have you tried?
I've looked at several issues, but I haven't solved my problem.
- #602
I use a sound of 0.2 seconds.
A sound of 1 second was inserted but did not work.
🪲 Please post your code:
// Please post your code
const sound = new Sound('beep.mp3', Sound.MAIN_BUNDLE, (error) => {
if (error) {
console.log('fail to load sound');
return ;
}
});
// in View
<Pressable onPress={() => sound.play((success) => {
if (success) {
console.log('successfully finished playing');
} else {
console.log('playback failed due to audio decoding errors');
}
})}
>
<Button...>
</Pressable>
💡 Possible solution
Is your issue with...
- iOS
- Android
- Windows
Are you using...
- React Native CLI (e.g.
react-native run-android
) - Expo
- Other: (please specify)
Which versions are you using?
- React Native Sound: 0.11.2
- React Native: 0.68.1
- iOS:
- Android:
- Windows:
Does the problem occur on...
- Simulator
- Device
If your problem is happening on a device, which device?
- Device: android 12
I got the idea here. And I succeeded.
#544
My solution is to make shrinkResources false. (android/app/bundle.gradle)
Sound is a resource that is stored locally and used. I don't know why it's being removed.