React-native-sound: App freezes on Android

Created on 14 Jul 2018  路  11Comments  路  Source: zmxv/react-native-sound

Hi!
On iOS works perfectly. But when I call "new Sound" on Android, app freezes and nothing logging to console. Has anyone had this problem?

var whoosh = new Sound('whoosh.mp3', Sound.MAIN_BUNDLE, (error) => {
  if (error) {
    console.log('failed to load the sound', error);
  } else {
    console.log('loaded successfully ')
  }
});

Most helpful comment

Sorry. I don't know why, but this problem with my device (xiaomi redmi 4a). I reboot it and library became works well.

All 11 comments

I check it in empty project and run on android device and I have this problem too. When I call new Sound my app freezes.

Sorry. I don't know why, but this problem with my device (xiaomi redmi 4a). I reboot it and library became works well.

@oxilor same issue in my xioami redmi 4a. any solution?

@adirzoari I just reboot my device and everything was okay. Try it.

@oxilor I reboot my device and still it freeze. weird.
if I delete the sound, everything works good.

@adirzoari What about another apps? Are they playing audio without freeze?

yes. I have many apps with sound and everything works good

@adirzoari try download app Lingain, add new word in "My vocabulary" tab and click to speaker. Is app freeze?

no. your app is not freeze. when i add new word I hear it and it works good.

@adirzoari It's weird. Try to create empty project and install react-native-sound manually. It should be works on Xiaomi Redmi 4a. I'm using react-native-sound like this.

thanks I will try. in your example, you used react-native-fs. for what?
i did this way (in debug mode it sometimes works and I hear the sound, in the release it freeze)

import Sound from 'react-native-sound'

export const playSound = (sound) => {
    const music = new Sound(sound, Sound.MAIN_BUNDLE, (error) => {
        if (error) {
            console.log('failed to load the sound', error);
            return;
        }
        // music.setVolume(0.8)
        // loaded successfully, play            
        music.play((success) => {
            console.log(success)
            if (success) {
                console.log('successfully finished playing');
                music.release();
            } else {
                console.log('playback failed due to audio decoding errors');
            }
        });
    });

}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

kurokky picture kurokky  路  3Comments

Jeremaiha picture Jeremaiha  路  5Comments

therealproblem picture therealproblem  路  5Comments

watadarkstar picture watadarkstar  路  3Comments

viperfx picture viperfx  路  4Comments