1

I'm working on a React Native application which plays back voicemails. I'm running into an issue with our production app. It does not play back the voicemails on the production iOS or testflight builds, however it will play back on the production build of android as well as the emulator for iOS and Android. I'm relatively new to react-native applications so I'm trying to figure out why this would be occurring.

The app does not crash, it shows the playback as occurring in the UI but no audio is played.

What are specific things to check regarding a production build not being able to play sound?

I am on the current version of react-native-sound which is currently 0.10.9.

Here is my togglePlay function which uses Sound from react-native-sound. I have imported it.

togglePlay() {

  if (this.state.vmLoaded == false) {

        if (this.state.vmLoading == true) {
            return;
        }

        if (this.state.vmLoading == false) {

            this.setState({ vmLoading: true });

            Requester.getVoicemail(this.props.vmData, this.props.token, 'stream')
            .then((res) => {

                this.setState({
                    vmPath: res,
                    vmLoaded: true,
                });

                const vm = new Sound(res, '', (error) => {

                    if (error) {

                        // Show toast if voicemail did not load
                        Toast({ message: 'Failed to load voicemail' });
                    } else {

                        if (!this.state.vmStarted) {

                            this.setState({ vmStarted: true });
                        }

                        vm.play((success) => {

                            if (success) {

                                this.setState({
                                    vmPlaying: false,
                                    currentTime: this.state.vmLength / 1000,
                                });

                                // Clears the interval timer to keep thread
                                // from keeping track of timing
                                timer.clearInterval(this, 'playingInt');
                            } else {

                                // if call recording fails to play, show toast to user
                                Toast({ message: 'Failed to play recording' });
                            }
                        });

                        this.setState({ vmPlaying: true });

                        // if loaded successfully, set the instance of Sound as STATE vm
                        // allowing calls to the instance via this.state.vm
                        // ie: this.state.vm.play() will initiate playing the sound
                        this.setState({
                            // set instance of Sound to state
                            vm,
                            // set full length of recording to state
                            vmLength: vm.getDuration(),
                            // set current playing time of recording to state (new, so zero)
                            currentTime: 0,
                            // interval is still null until sound is played
                            interval: null,
                            // sound starts off paused (no audio)
                            vmPlaying: true,
                            // Finally, the recording has been loaded, setting
                            // this so another instance is not created on
                            // rerender (see above IF statements)
                            vmLoaded: true,
                            vmLoading: false,
                        });
                    }
                });
            }).then(() => {

                timer.clearInterval(this, 'playingInt');

                interval: timer.setInterval(this, 'playingInt', () => {

                    this.state.vm.getCurrentTime((seconds) => {

                        this.setState({ currentTime: seconds });
                    });
                }, 1000);
            });
        }
    } else if (this.state.vmLoaded == true) {

        if (this.state.vmPlaying == true) {

            this.state.vm.pause();

            this.setState({ vmPlaying: false });

            timer.clearInterval(this, 'playingInt');
        } else {

            this.state.vm.play();

            this.setState({ vmPlaying: true });

            timer.clearInterval(this, 'playingInt');

            interval: timer.setInterval(this, 'playingInt', () => {

                this.state.vm.getCurrentTime((seconds) => {

                    this.setState({ currentTime: seconds });
                });
            }, 1000);
        }
    }
}

Please let me know if other information would be helpful in debugging this.

Thank you

brooks
  • 21
  • 1
  • 6
  • Update: When the app is deleted and then rebuilt the sound does not play on ios but any subsequent builds to the app (without deleting it) will allow the sound to play. – brooks Nov 13 '18 at 00:14
  • Why do you provide your package.json ? Isn't your question about `react-native-sound` ? What exact version of it do you use / is resolved in your package-lock.json ? Could you provide the Javascript code where you use it ? We use react-native-sound, and we had no problems so far (except with codepush releases on android...) – Vinzzz Nov 13 '18 at 09:40
  • @Vinzzz I updated my question with the updated info you asked for. I call togglePlay() within a ToughableHighlight component. Again this works great on Android builds but not on iOS. Thanks for your help – brooks Nov 13 '18 at 18:06
  • You didn't provide the react-native-sound part, this is only some react component. Do you use require as sound filePath? How do you embed sounds in you app bundle ? – Vinzzz Nov 14 '18 at 00:48
  • I figured out the issue for this. Sound was coming out of the speaker on the phone instead of the earpiece and the ringer was muted. I added `Sound.setCategory("Playback") to allow the sound to still play back even when the ringer was muted. Thank you for offering to assist this problem @Vinzzz – brooks Nov 15 '18 at 16:20
  • No problem, Glad you could sort it out :) – Vinzzz Nov 16 '18 at 19:31

2 Answers2

1

The problem had to to do with the manual switch to mute the ringer on iPhone. Sound was being played back through the speakerphone. I added `Sound.setCategory("Playback") after Sound was initialized to allow the sound to still play back even with the ringer muted.

brooks
  • 21
  • 1
  • 6
1

I recently faced this issue and none of the responses available online worked for me. At the end, I realized that the .mp3 sounds that I used were not being detected by mac/Xcode. So, when you see file details in Xcode or Finder, it was not able to identify enough information like duration. After spending hours looking for the solution. I found this issue.

What I did wrong - Renamed *.wav or *.avi files to .mp3 manually

Solution - 1. Use iTunes to convert files to a specific format. Manually converting file formats corrupts the file and though they work on android, iOS fails to detect them after archiving the build. 2. For iOS, Add your sounds to Resources in Xcode project

Pouya Danesh
  • 1,557
  • 2
  • 19
  • 36
  • I think this can also happen if you use some online audio converters. I was trying to convert .mp3 to .wav, and the converted .wav wasn't playing. Just using the original .mp3 worked for me. – Devon Aug 24 '22 at 02:59