我刚接触react-native,正在尝试创建一个音频播放应用程序。
我使用react-native-sound来实现同样的目的。在文档中,它指定我可以从网络播放该文件。但我找不到任何与此相同的文档。
现在,我正在从ROR后台上传音频文件,并将文件添加到react中的本地文件夹中。我正在将其更改为aws s3。
音频文件是这样启动的-
var whoosh = new Sound(this.state.soundFile, Sound.MAIN_BUNDLE, (error) => {其中this.state.soundFile是指定文件夹内的本地文件名(字符串)。
这个是可能的吗?
发布于 2017-05-16 23:32:37
您可以通过指定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发布于 2019-08-02 13:04:09
import Sound from 'react-native-sound';
const sound = new Sound('http://sounds.com/some-sound', null, (error) => {
if (error) {
// do something
}
// play when loaded
sound.play();
});https://stackoverflow.com/questions/43994230
复制相似问题