react-native - 如何在反应原生和相对错误中添加声音
问题描述
我们如何在 React Native 中添加声音?我正在使用下面的代码,但它总是给出错误= 未定义不是一个对象(评估'Howler._navigator.appVersion.match')
. 我正在使用下面的代码:(使用howler依赖),我也尝试使用“react-native-sound”依赖,但它给出了同样的错误。
import React from 'react';
import { StyleSheet, Text, View, Image ,TouchableOpacity} from 'react-native';
import { Howler, Howl } from 'howler';
import a from '../../assets/audios/a.mp3';
const timePass=function (){
var sound = new Howl({
src: [a]
});
return <View>
<TouchableOpacity style={{}} activeOpacity={0.8} onPress={()=>sound.play()}>
<Text>Sound</Text>
</TouchableOpacity>
</View>
}
const style=StyleSheet.create({ });
export default timePass;```
解决方案
推荐阅读
- wordpress - 按 menu_order + 流行度对 WooCommerce 产品进行排序
- javascript - 如果两个相邻的可编辑跨度和光标在中间,html如何决定我在写哪一个?
- c++ - Qt获取样式表边框颜色
- django - Django应用程序中Highcharts图中的X轴标签
- visual-studio-code - vscode如何在一个扩展中调用其他扩展
- javascript - 如何使用 map 函数迭代嵌套对象?
- css - CSS rCharts 调整与 R renderChart{} 中的 staggerLabel 函数重叠
- ruby - 使用二维数组中的最大元素数查找非空交集
- android - 单击按钮后需要帮助绑定按钮,数据来自retrofit2 api调用
- swift - 对表示为数组的对象的 Swift Codable 支持