React native react native-require()必须具有单字符串文字参数
我正在使用Expo在React Native中编写一个采样器应用程序,遇到以下错误:React native react native-require()必须具有单字符串文字参数,react-native,React Native,我正在使用Expo在React Native中编写一个采样器应用程序,遇到以下错误: react native-require()必须具有单字符串文字参数 预录样本的播放方式如下: const SAMPLES = [ { name: 'air horn', uri: require('../samples/air_horn.mp3') }, { name: 'rim shot', uri: require('../samples/rimshot.mp3') }, ] playSam
react native-require()必须具有单字符串文字参数
预录样本的播放方式如下:
const SAMPLES = [
{ name: 'air horn', uri: require('../samples/air_horn.mp3') },
{ name: 'rim shot', uri: require('../samples/rimshot.mp3') },
]
playSample = (uri) => {
const { soundObject, status } = Expo.Audio.Sound.create(
uri,
{ shouldPlay: true }
)
}
这是基于某种程度上,工作良好。但是,我也希望用户记录自己的示例,这意味着它来自一个自定义URL:
playCustomSample = () => {
const customSample = this.props.navigation.state.params
? require(this.props.navigation.state.params.custom.toString())
: require('./samples/blank.mp3')
try {
const { soundObject, status } = Expo.Audio.Sound.create(
customSample,
{ shouldPlay: true }
)
} catch(error) {
console.log('ERROR:', error)
}
当我记录导航传递的custom
param时,它就在那里。所以我发现我在概念上做得不对,require()
需要一个字符串,但在记录之前我不会知道文件的名称/位置
如何在不提前知道链接的情况下访问音频文件,以便将其包括在内
此外,我无法访问Mac电脑,因此无法将其从Expo中弹出,因此不能使用react-native audio或react-native sound等功能。可能会复制