我正在开发一个播放语音邮件的 React Native 应用程序。我遇到了我们的生产应用程序的问题。它不会在生产 iOS 或 testflight 版本上播放语音邮件,但它会在 android 的生产版本以及 iOS 和 Android 模拟器上播放。我对 react-native 应用程序比较陌生,所以我试图弄清楚为什么会发生这种情况。
该应用程序不会崩溃,它会在 UI 中显示播放,但没有播放音频。
关于无法播放声音的生产版本,需要检查哪些具体事项?
我在当前版本的 react-native-sound 上,目前是 0.10.9。
这是我的 togglePlay 函数,它使用来自 react-native-sound 的声音。我已经导入了。
切换播放(){
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);
}
}
}
如果其他信息有助于调试,请告诉我。
谢谢