Javascript React Native-世博会音频API问题与远程音频uri:&x201C;服务器配置不正确”;
使用Expo audio API,我遇到了从远程服务器url播放音频文件的问题。在故障排除过程中,我手动复制了文件并测试了require(local_file_path),效果很好,所以问题出在远程服务器上 相关本机代码如下:Javascript React Native-世博会音频API问题与远程音频uri:&x201C;服务器配置不正确”;,javascript,node.js,react-native,expo,Javascript,Node.js,React Native,Expo,使用Expo audio API,我遇到了从远程服务器url播放音频文件的问题。在故障排除过程中,我手动复制了文件并测试了require(local_file_path),效果很好,所以问题出在远程服务器上 相关本机代码如下: const playbackObject = await Audio.Sound.create( // require('../assets/audio/recording-1234.caf'), { uri: 'http://xx.x.x.xxx
const playbackObject = await Audio.Sound.create(
// require('../assets/audio/recording-1234.caf'),
{ uri: 'http://xx.x.x.xxx:5000/api/file/recording-1234.caf'},
{ shouldPlay: true }
);
我的服务器是一个nodeJS/expressapi。端点仅在本地服务器文件系统中找到正确的文件,并将响应流式返回:
app.get('/api/file/:filename', function (req, res) {
const fileName = req.params.filename
const src = fs.createReadStream('./files/audio/' + fileName);
res.setHeader( 'content-type', 'audio/x-caf')
src.pipe(res);
//'audio/x-caf'
})
我的所有音频文件都是.caf文件,因为它们源自设备上的录制。我可以从服务器日志中看到GET请求正在通过。我想这只是不喜欢我的回答
我收到的错误是:
YellowBox.js:80 Possible Unhandled Promise Rejection (id: 0):
Error: The server is not correctly configured. - The AVPlayerItem instance has failed with the error code -11850 and domain "AVFoundationErrorDomain".
Error: The server is not correctly configured. - The AVPlayerItem instance has failed with the error code -11850 and domain "AVFoundationErrorDomain".
at loadError (blob:http://localhost:19001/d3b3b86a-aac6-4b17-9f10-57945e3b1958:104934:28)
at MessageQueue.__invokeCallback (blob:http://localhost:19001/d3b3b86a-aac6-4b17-9f10-57945e3b1958:2800:18)
at blob:http://localhost:19001/d3b3b86a-aac6-4b17-9f10-57945e3b1958:2545:18
at MessageQueue.__guardSafe (blob:http://localhost:19001/d3b3b86a-aac6-4b17-9f10-57945e3b1958:2713:11)
at MessageQueue.invokeCallbackAndReturnFlushedQueue (blob:http://localhost:19001/d3b3b86a-aac6-4b17-9f10-57945e3b1958:2544:14)
at http://localhost:19001/debugger-ui/debuggerWorker.js:70:58
我的服务器配置不正确吗?我可以不流文件吗?Expo文档没有任何关于它期望的HTTP响应类型的信息,我也不知道如何解决这个问题
非常感谢您的帮助