zmxv / react-native-sound

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

Fail to load sound in Android apk. { extra: -2147483648, what: 1 } #818

Closed Arthur-Noh closed 1 year ago

Arthur-Noh commented 1 year ago

:beetle: 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?

:beetle: What have you tried?

I've looked at several issues, but I haven't solved my problem.

  1. https://github.com/zmxv/react-native-sound/issues/602 I use a sound of 0.2 seconds. A sound of 1 second was inserted but did not work.

:beetle: 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>

:bulb: Possible solution

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?

Arthur-Noh commented 1 year ago

I got the idea here. And I succeeded. https://github.com/zmxv/react-native-sound/issues/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.