Reputation: 21
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
Upvotes: 1
Views: 3575
Reputation: 21
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
Upvotes: 1
Reputation: 21
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.
Upvotes: 1