我是本机反应新手,正在尝试创建音频播放应用。
我使用react-native-sound实现了相同目的。在文档中,它指定我可以从网络播放文件。但我找不到相同的任何文档。
现在,我正在从ROR后端上传音频文件,并将该文件添加到react内部的本地文件夹中。
我将其更改为AWS S3。
音频文件开始像-
var whoosh = new Sound(this.state.soundFile, Sound.MAIN_BUNDLE, (error) => {
其中
this.state.soundFile
是指定文件夹内的本地文件名(字符串)。这可能吗?
最佳答案
您可以通过指定url而不设置 bundle 包来播放带有react-native-sound的远程声音:
import React, { Component } from 'react'
import { Button } from 'react-native'
import Sound from 'react-native-sound'
class RemoteSound extends Component {
playTrack = () => {
const track = new Sound('https://www.soundjay.com/button/button-1.mp3', null, (e) => {
if (e) {
console.log('error loading track:', e)
} else {
track.play()
}
})
}
render() {
return <Button title="play me" onPress={this.playTrack} />
}
}
export default RemoteSound