zmxv / react-native-sound

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

App freezes on Android #462

Open oxilor opened 6 years ago

oxilor commented 6 years ago

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 ')
  }
});
oxilor commented 6 years ago

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.

oxilor commented 6 years ago

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

adirzoari commented 6 years ago

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

oxilor commented 6 years ago

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

adirzoari commented 6 years ago

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

oxilor commented 6 years ago

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

adirzoari commented 6 years ago

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

oxilor commented 6 years ago

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

adirzoari commented 6 years ago

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

oxilor commented 6 years ago

@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.

adirzoari commented 6 years ago

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');
            }
        });
    });

}