首页 > 解决方案 > 如何在反应原生和相对错误中添加声音

问题描述

我们如何在 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;```

标签: react-nativeexpohowler.jsreact-native-sound

解决方案


推荐阅读