我正在使用react-native-audio-recorder-player并且我正在使用
const playAudio = useCallback(async audio => {
try {
const bro = await audioRecorderPlayer.startPlayer(
audio
);
console.log(bro, 'has prob');
await audioRecorderPlayer.setVolume(1.0);
await audioRecorderPlayer.addPlayBackListener(async e => {
if (e.currentPosition === e.duration) {
console.error((e.currentPosition === e.duration).toString());
await audioRecorderPlayer.stopPlayer();
await audioRecorderPlayer.removePlayBackListener();
dispatch(stop());
dispatch(setCurrentPosSec(0));
dispatch(setCurrentDurationSec(0));
dispatch(setPlayTime('00:00:00'));
dispatch(setDuration(audioRecorderPlayer.mmssss(0)));
return;
}
dispatch(setCurrentPosSec(e.currentPosition));
dispatch(setCurrentDurationSec(e.duration));
dispatch(
setPlayTime(
audioRecorderPlayer.mmssss(Math.floor(e.currentPosition)),
),
);
dispatch(
setDuration(audioRecorderPlayer.mmssss(Math.floor(e.duration))),
);
});
} catch (err) {
console.log('net', err);
dispatch(stop());
}
}, []);
当我们从React Native录制时,它工作正常,但是当我尝试使用React播放从网络录制的音频时,问题就出现了,但是音频在React应用程序中工作正常,该应用程序是通过Web本身录制的,但在React中本机应用程序无法正常工作。
经过深入研究,我找到了 React Native Audio Recorder Player 不播放网络录制音频问题的解决方案。利用 https://github.com/yusitnikov/fix-webm-duration 有效解决了该问题。该存储库提供了必要的修复,确保在 React Native 环境中无缝播放录制的音频。